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,348 @@
<?php
/**
* Function
*
* @package POPMAKE_EMODAL
* @subpackage Functions/Import
* @copyright Copyright (c) 2023, Code Atlantic LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Import
*
* Runs on plugin install by setting up the post types, custom taxonomies,
* flushing rewrite rules also creates the plugin and populates the settings
* fields for those plugin pages. After successful install, the user is
* redirected to the POPMAKE_EMODAL Welcome screen.
*
* @since 1.0
* @global $wpdb
* @global $popmake_options
* @global $wp_version
* @return void
*/
function popmake_emodal_v2_import() {
global $wpdb, $popmake_options, $wp_version, $popmake_tools_page;
require_once POPMAKE_DIR . 'includes/importer/easy-modal-v2/functions.php';
if ( ! class_exists( 'EModal_Model' ) ) {
require_once POPMAKE_DIR . '/includes/importer/easy-modal-v2/model.php';
}
if ( ! class_exists( 'EModal_Model_Modal' ) ) {
require_once POPMAKE_DIR . '/includes/importer/easy-modal-v2/model/modal.php';
}
if ( ! class_exists( 'EModal_Model_Theme' ) ) {
require_once POPMAKE_DIR . '/includes/importer/easy-modal-v2/model/theme.php';
}
if ( ! class_exists( 'EModal_Model_Theme_Meta' ) ) {
require_once POPMAKE_DIR . '/includes/importer/easy-modal-v2/model/theme/meta.php';
}
if ( ! class_exists( 'EModal_Model_Modal_Meta' ) ) {
require_once POPMAKE_DIR . '/includes/importer/easy-modal-v2/model/modal/meta.php';
}
$themes = get_all_modal_themes( '1 = 1' );
$theme_id_map = [];
foreach ( $themes as $Theme ) {
$theme = $Theme->as_array();
$meta = $theme['meta'];
$theme_meta = apply_filters(
'popmake_emodal_import_theme_meta',
[
'popup_theme_defaults_set' => true,
'popup_theme_overlay_background_color' => $meta['overlay']['background']['color'],
'popup_theme_overlay_background_opacity' => $meta['overlay']['background']['opacity'],
'popup_theme_container_padding' => $meta['container']['padding'],
'popup_theme_container_background_color' => $meta['container']['background']['color'],
'popup_theme_container_background_opacity' => $meta['container']['background']['opacity'],
'popup_theme_container_border_radius' => $meta['container']['border']['radius'],
'popup_theme_container_border_style' => $meta['container']['border']['style'],
'popup_theme_container_border_color' => $meta['container']['border']['color'],
'popup_theme_container_border_width' => $meta['container']['border']['width'],
'popup_theme_container_boxshadow_inset' => $meta['container']['boxshadow']['inset'],
'popup_theme_container_boxshadow_horizontal' => $meta['container']['boxshadow']['horizontal'],
'popup_theme_container_boxshadow_vertical' => $meta['container']['boxshadow']['vertical'],
'popup_theme_container_boxshadow_blur' => $meta['container']['boxshadow']['blur'],
'popup_theme_container_boxshadow_spread' => $meta['container']['boxshadow']['spread'],
'popup_theme_container_boxshadow_color' => $meta['container']['boxshadow']['color'],
'popup_theme_container_boxshadow_opacity' => $meta['container']['boxshadow']['opacity'],
'popup_theme_title_font_color' => $meta['title']['font']['color'],
'popup_theme_title_line_height' => $meta['title']['font']['size'],
'popup_theme_title_font_size' => $meta['title']['font']['size'],
'popup_theme_title_font_family' => $meta['title']['font']['family'],
'popup_theme_title_font_weight' => $meta['title']['font']['weight'],
'popup_theme_title_font_style' => $meta['title']['font']['style'],
'popup_theme_title_text_align' => $meta['title']['text']['align'],
'popup_theme_title_textshadow_horizontal' => $meta['title']['textshadow']['horizontal'],
'popup_theme_title_textshadow_vertical' => $meta['title']['textshadow']['vertical'],
'popup_theme_title_textshadow_blur' => $meta['title']['textshadow']['blur'],
'popup_theme_title_textshadow_color' => $meta['title']['textshadow']['color'],
'popup_theme_title_textshadow_opacity' => $meta['title']['textshadow']['opacity'],
'popup_theme_content_font_color' => $meta['content']['font']['color'],
'popup_theme_content_font_family' => $meta['content']['font']['family'],
'popup_theme_content_font_weight' => $meta['content']['font']['weight'],
'popup_theme_content_font_style' => $meta['content']['font']['style'],
'popup_theme_close_text' => $meta['close']['text'],
'popup_theme_close_padding' => $meta['close']['padding'],
'popup_theme_close_location' => $meta['close']['location'],
'popup_theme_close_position_top' => $meta['close']['position']['top'],
'popup_theme_close_position_left' => $meta['close']['position']['left'],
'popup_theme_close_position_bottom' => $meta['close']['position']['bottom'],
'popup_theme_close_position_right' => $meta['close']['position']['right'],
'popup_theme_close_line_height' => $meta['close']['font']['size'],
'popup_theme_close_font_color' => $meta['close']['font']['color'],
'popup_theme_close_font_size' => $meta['close']['font']['size'],
'popup_theme_close_font_family' => $meta['close']['font']['family'],
'popup_theme_close_font_weight' => $meta['close']['font']['weight'],
'popup_theme_close_font_style' => $meta['close']['font']['style'],
'popup_theme_close_background_color' => $meta['close']['background']['color'],
'popup_theme_close_background_opacity' => $meta['close']['background']['opacity'],
'popup_theme_close_border_radius' => $meta['close']['border']['radius'],
'popup_theme_close_border_style' => $meta['close']['border']['style'],
'popup_theme_close_border_color' => $meta['close']['border']['color'],
'popup_theme_close_border_width' => $meta['close']['border']['width'],
'popup_theme_close_boxshadow_inset' => $meta['close']['boxshadow']['inset'],
'popup_theme_close_boxshadow_horizontal' => $meta['close']['boxshadow']['horizontal'],
'popup_theme_close_boxshadow_vertical' => $meta['close']['boxshadow']['vertical'],
'popup_theme_close_boxshadow_blur' => $meta['close']['boxshadow']['blur'],
'popup_theme_close_boxshadow_spread' => $meta['close']['boxshadow']['spread'],
'popup_theme_close_boxshadow_color' => $meta['close']['boxshadow']['color'],
'popup_theme_close_boxshadow_opacity' => $meta['close']['boxshadow']['opacity'],
'popup_theme_close_textshadow_horizontal' => $meta['close']['textshadow']['horizontal'],
'popup_theme_close_textshadow_vertical' => $meta['close']['textshadow']['vertical'],
'popup_theme_close_textshadow_blur' => $meta['close']['textshadow']['blur'],
'popup_theme_close_textshadow_color' => $meta['close']['textshadow']['color'],
'popup_theme_close_textshadow_opacity' => $meta['close']['textshadow']['opacity'],
],
$Theme
);
$new_theme_id = wp_insert_post(
[
'post_title' => $theme['name'],
'post_status' => $theme['is_trash'] ? 'trash' : 'publish',
'post_author' => get_current_user_id(),
'post_type' => 'popup_theme',
'comment_status' => 'closed',
]
);
foreach ( $theme_meta as $meta_key => $meta_value ) {
update_post_meta( $new_theme_id, $meta_key, $meta_value );
}
update_post_meta( $new_theme_id, 'popup_theme_old_easy_modal_id', $theme['id'] );
$theme_id_map[ $theme['id'] ] = $new_theme_id;
}
if ( count( $themes ) === 1 ) {
update_post_meta( $new_theme_id, 'popup_theme_defaults_set', true );
update_option( 'popmake_default_theme', $new_theme_id );
}
$modals = get_all_modals( '1 = 1' );
// echo '<pre>'; var_export(popmake_popup_meta_fields()); echo '</pre>';
foreach ( $modals as $Modal ) {
$modal = $Modal->as_array();
$meta = $modal['meta'];
$modal_meta = apply_filters(
'popmake_emodal_import_modal_meta',
[
'popup_old_easy_modal_id' => $modal['id'],
'popup_defaults_set' => true,
'popup_theme' => isset( $theme_id_map[ $theme['id'] ] ) ? $theme_id_map[ $theme['id'] ] : null,
'popup_title' => $modal['title'],
'popup_display_scrollable_content' => null,
'popup_display_overlay_disabled' => $meta['display']['overlay_disabled'],
'popup_display_size' => $meta['display']['size'],
'popup_display_responsive_min_width' => '',
'popup_display_responsive_min_width_unit' => 'px',
'popup_display_responsive_max_width' => '',
'popup_display_responsive_max_width_unit' => 'px',
'popup_display_custom_width' => $meta['display']['custom_width'],
'popup_display_custom_width_unit' => $meta['display']['custom_width_unit'],
'popup_display_custom_height' => $meta['display']['custom_height'],
'popup_display_custom_height_unit' => $meta['display']['custom_height_unit'],
'popup_display_custom_height_auto' => $meta['display']['custom_height_auto'],
'popup_display_location' => $meta['display']['location'],
'popup_display_position_top' => $meta['display']['position']['top'],
'popup_display_position_left' => $meta['display']['position']['left'],
'popup_display_position_bottom' => $meta['display']['position']['bottom'],
'popup_display_position_right' => $meta['display']['position']['right'],
'popup_display_position_fixed' => $meta['display']['position']['fixed'],
'popup_display_animation_type' => $meta['display']['animation']['type'],
'popup_display_animation_speed' => $meta['display']['animation']['speed'],
'popup_display_animation_origin' => $meta['display']['animation']['origin'],
'popup_close_overlay_click' => $meta['close']['overlay_click'],
'popup_close_esc_press' => $meta['close']['esc_press'],
'popup_close_f4_press' => null,
],
$Modal
);
if ( 1 === $modal['is_sitewide'] ) {
$modal_meta['popup_targeting_condition_on_entire_site'] = true;
}
$new_modal_id = wp_insert_post(
[
'post_title' => $modal['name'],
'post_status' => $modal['is_trash'] ? 'trash' : 'publish',
'post_content' => $modal['content'],
'post_author' => get_current_user_id(),
'post_type' => 'popup',
'comment_status' => 'closed',
]
);
foreach ( $modal_meta as $meta_key => $meta_value ) {
update_post_meta( $new_modal_id, $meta_key, $meta_value );
}
}
}
function popmake_emodal_init() {
if ( pum_get_option( 'enable_easy_modal_compatibility_mode' ) ) {
if ( ! shortcode_exists( 'modal' ) ) {
add_shortcode( 'modal', 'popmake_emodal_shortcode_modal' );
}
add_filter( 'pum_popup_data_attr', 'popmake_emodal_get_the_popup_data_attr', 10, 2 );
add_filter( 'popmake_shortcode_popup_default_atts', 'popmake_emodal_shortcode_popup_default_atts', 10, 2 );
add_filter( 'popmake_shortcode_data_attr', 'popmake_emodal_shortcode_data_attr', 10, 2 );
add_filter( 'pum_popup_is_loadable', 'popmake_emodal_popup_is_loadable', 20, 2 );
}
}
add_action( 'init', 'popmake_emodal_init' );
function popmake_emodal_popup_is_loadable( $return, $popup_id ) {
global $post;
if ( empty( $post ) || ! isset( $post->ID ) ) {
return $return;
}
$easy_modal_id = get_post_meta( $popup_id, 'popup_old_easy_modal_id', true );
$post_modals = get_post_meta( $post->ID, 'easy-modal_post_modals', true );
if ( ! $easy_modal_id || empty( $post_modals ) || ! in_array( $easy_modal_id, $post_modals ) ) {
return $return;
}
return true;
}
function popmake_emodal_get_the_popup_data_attr( $data_attr, $popup_id ) {
$easy_modal_id = get_post_meta( $popup_id, 'popup_old_easy_modal_id', true );
if ( ! $easy_modal_id ) {
return $data_attr;
}
return array_merge(
$data_attr,
[
'old_easy_modal_id' => $easy_modal_id,
]
);
}
function popmake_emodal_shortcode_modal( $atts, $content = null ) {
$atts = shortcode_atts(
apply_filters(
'emodal_shortcode_modal_default_atts',
[
'id' => '',
'theme_id' => null,
'title' => null,
'overlay_disabled' => null,
'size' => null,
'width' => null,
'widthUnit' => null,
'height' => null,
'heightUnit' => null,
'location' => null,
'positionTop' => null,
'positionLeft' => null,
'positionBottom' => null,
'positionRight' => null,
'positionFixed' => null,
'animation' => null,
'animationSpeed' => null,
'animationOrigin' => null,
'overlayClose' => null,
'escClose' => null,
// Deprecated
'theme' => null,
'duration' => null,
'direction' => null,
'overlayEscClose' => null,
]
),
apply_filters( 'emodal_shortcode_modal_atts', $atts )
);
$new_shortcode_atts = [
'id' => $atts['id'],
'emodal_id' => $atts['id'],
'theme_id' => $atts['theme_id'],
'title' => $atts['title'],
'overlay_disabled' => $atts['overlay_disabled'],
'size' => $atts['size'],
'width' => $atts['width'],
'width_unit' => $atts['widthUnit'],
'height' => $atts['height'],
'height_unit' => $atts['heightUnit'],
'location' => $atts['location'],
'position_top' => $atts['positionTop'],
'position_left' => $atts['positionLeft'],
'position_bottom' => $atts['positionBottom'],
'position_right' => $atts['positionRight'],
'position_fixed' => $atts['positionFixed'],
'animation_type' => $atts['animation'],
'animation_speed' => $atts['animationSpeed'],
'animation_origin' => $atts['animationOrigin'],
'overlay_click' => $atts['overlayClose'],
'esc_press' => $atts['escClose'],
];
$shortcode = '[popup ';
foreach ( $new_shortcode_atts as $attr => $val ) {
if ( $val && ! empty( $val ) ) {
$shortcode .= $attr . '="' . $val . '" ';
}
}
$shortcode .= ']' . $content . '[/popup]';
return do_shortcode( $shortcode );
}
function popmake_emodal_shortcode_popup_default_atts( $default_atts = [] ) {
return array_merge(
$default_atts,
[
'emodal_id' => null,
]
);
}
function popmake_emodal_shortcode_data_attr( $data, $attr ) {
if ( ! empty( $attr['emodal_id'] ) ) {
$data['old_easy_modal_id'] = $attr['emodal_id'];
}
return $data;
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* Importer for easy-modal functions
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! function_exists( 'get_all_modals' ) ) {
function enqueue_modal( $id ) {
if ( ! is_array( $id ) ) {
EModal_Modals::enqueue_modal( $id );
} else {
foreach ( $id as $i ) {
EModal_Modals::enqueue_modal( $i );
}
}
}
}
if ( ! function_exists( 'emodal_get_option' ) ) {
function emodal_get_option( $key ) {
global $blog_id;
if ( function_exists( 'is_multisite' ) && is_multisite() && $blog_id ) {
return get_blog_option( $blog_id, $key );
} else {
return get_site_option( $key );
}
}
}
if ( ! function_exists( 'emodal_update_option' ) ) {
function emodal_update_option( $key, $value ) {
global $blog_id;
if ( function_exists( 'is_multisite' ) && is_multisite() && $blog_id ) {
return update_blog_option( $blog_id, $key, $value );
} else {
return update_site_option( $key, $value );
}
}
}
if ( ! function_exists( 'emodal_delete_option' ) ) {
function emodal_delete_option( $key ) {
global $blog_id;
if ( function_exists( 'is_multisite' ) && is_multisite() && $blog_id ) {
return delete_blog_option( $blog_id, $key );
} else {
return delete_site_option( $key );
}
}
}
if ( ! function_exists( 'emodal_get_license' ) ) {
function emodal_get_license( $key = null ) {
$license = emodal_get_option( EMCORE_SLUG . '-license' );
if ( ! $license ) {
$license = [
'valid' => false,
'key' => '',
'status' => [
'code' => null,
'message' => null,
'expires' => null,
'domains' => null,
],
];
emodal_update_option( EMCORE_SLUG . '-license', $license );
}
return $license && $key ? emresolve( $license, $key ) : $license;
}
}
if ( ! function_exists( 'emresolve' ) ) {
function emresolve( array $a, $path, $default = null ) {
$current = $a;
$p = strtok( $path, '.' );
while ( false !== $p ) {
if ( ! isset( $current[ $p ] ) ) {
return $default;
}
$current = $current[ $p ];
$p = strtok( '.' );
}
return $current;
}
}

View File

@@ -0,0 +1,167 @@
<?php
/**
* Importer for easy-modal model
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class EModal_Model {
protected $_class_name = 'EModal_Model';
protected $_table_name = '';
protected $_pk = 'id';
protected $_data = [];
protected $_default_fields = [];
protected $_state = null;
public function __construct( $id = null, $limit = 1 ) {
global $wpdb;
$table_name = $wpdb->prefix . $this->_table_name;
$class_name = strtolower( $this->_class_name );
$this->_data = apply_filters( "{$class_name}_fields", $this->_default_fields );
if ( $id && is_numeric( $id ) ) {
$row = $wpdb->get_row( "SELECT * FROM $table_name WHERE $this->_pk = $id LIMIT 1", ARRAY_A );
if ( $row[ $this->_pk ] ) {
$this->process_load( $row );
}
} else {
$this->set_fields( apply_filters( "{$class_name}_defaults", [] ) );
}
return $this;
}
public function load( $query = null ) {
global $wpdb;
$table_name = $wpdb->prefix . $this->_table_name;
if ( ! $query ) {
$query = "SELECT * FROM $table_name";
}
$rows = $wpdb->get_results( $query, ARRAY_A );
if ( ! empty( $rows ) ) {
$results = [];
foreach ( $rows as $row ) {
$model = new $this->_class_name();
$model->process_load( $row );
$results[] = $model;
}
return $results;
}
return [];
}
public function save() {
global $wpdb;
$table_name = $wpdb->prefix . $this->_table_name;
if ( $this->id ) {
if ( ! $wpdb->update( $table_name, $this->serialized_values(), [ $this->_pk => $this->{$this->_pk} ] ) ) {
$wpdb->insert( $table_name, $this->serialized_values() );
$this->id = $wpdb->insert_id;
}
} else {
$wpdb->insert( $table_name, $this->serialized_values() );
$this->id = $wpdb->insert_id;
}
}
public function delete() {
global $wpdb;
$table_name = $wpdb->prefix . $this->_table_name;
return $wpdb->delete( $table_name, [ $this->_pk => $this->{$this->_pk} ] );
}
public function as_array() {
$values = $this->_data;
foreach ( $values as $key => $value ) {
$values[ $key ] = $this->$key;
}
return $values;
}
public function process_load( $data ) {
foreach ( $data as $key => $val ) {
if ( array_key_exists( $key, $this->_data ) ) {
$this->$key = maybe_unserialize( $val );
}
}
}
public function serialized_values() {
$values = $this->_data;
foreach ( $values as $key => $value ) {
if ( 'id' !== $key ) {
$values[ $key ] = maybe_serialize( $this->$key );
}
}
return $values;
}
public function __get( $key ) {
if ( array_key_exists( $key, $this->_data ) ) {
return $this->_data[ $key ];
} elseif ( 'id' === $key ) {
if ( array_key_exists( $this->_pk, $this->_data ) ) {
return $this->_data[ $this->_pk ];
}
}
}
public function __set( $key, $value ) {
if ( array_key_exists( $key, $this->_data ) ) {
$this->_data[ $key ] = $value;
return;
}
}
public function __isset( $name ) {
return isset( $this->_data[ $name ] );
}
public function fields() {
return array_keys( $this->_data );
}
public function set_fields( array $data ) {
foreach ( $data as $key => $val ) {
if ( array_key_exists( $key, $this->_data ) ) {
if ( is_array( $this->$key ) && is_array( $val ) ) {
$this->$key = array_replace_recursive( $this->$key, $val );
} else {
$this->$key = $val;
}
}
}
}
// Array Access Interface
public function offsetExists( $key ) {
return array_key_exists( $key, $this->as_array() );
}
public function offsetSet( $key, $value ) {
$this->__set( $key, $value );
}
public function offsetGet( $key ) {
return $this->$key;
}
public function offsetUnset( $key ) {
$this->_data[ $key ] = null;
}
}

View File

@@ -0,0 +1,135 @@
<?php
/**
* Importer for easy-modal model modal
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class EModal_Model_Modal extends EModal_Model {
protected $_class_name = 'EModal_Model_Modal';
protected $_table_name = 'em_modals';
protected $meta;
protected $_default_fields = [
'id' => null,
'theme_id' => 1,
'name' => '',
'title' => '',
'content' => '',
'created' => '0000-00-00 00:00:00',
'modified' => '0000-00-00 00:00:00',
'is_sitewide' => 0,
'is_system' => 0,
'is_trash' => 0,
];
public function __construct( $id = null ) {
parent::__construct( $id );
$this->load_meta();
return $this;
}
public function __get( $key ) {
if ( 'meta' === $key ) {
return $this->meta;
} else {
return parent::__get( $key );
}
}
public function save() {
if ( ! $this->id ) {
$this->created = date( 'Y-m-d H:i:s' );
}
$this->modified = date( 'Y-m-d H:i:s' );
parent::save();
$this->meta->modal_id = $this->id;
$this->meta->save();
}
public function load_meta() {
if ( empty( $this->meta ) ) {
$this->meta = new EModal_Model_Modal_Meta( $this->id );
}
return $this->meta;
}
public function as_array() {
$array = parent::as_array();
$array['meta'] = $this->meta->as_array();
return $array;
}
public function set_fields( array $data ) {
if ( ! empty( $data['meta'] ) ) {
$this->meta->set_fields( $data['meta'] );
}
parent::set_fields( $data );
}
}
if ( ! function_exists( 'get_all_modals' ) ) {
function get_all_modals( $where = 'is_trash != 1' ) {
global $wpdb;
$modals = [];
$modal_ids = [];
$EModal_Model_Modal = new EModal_Model_Modal();
$EModal_Model_Modal_Meta = new EModal_Model_Modal_Meta();
foreach ( $EModal_Model_Modal->load( "SELECT * FROM {$wpdb->prefix}em_modals" . ( $where ? ' WHERE ' . $where : '' ) ) as $modal ) {
$modals[ $modal->id ] = $modal;
$modal_ids[] = $modal->id;
}
if ( count( $modals ) ) {
foreach ( $EModal_Model_Modal_Meta->load( "SELECT * FROM {$wpdb->prefix}em_modal_metas WHERE modal_id IN (" . implode( ',', $modal_ids ) . ')' ) as $meta ) {
$modals[ $meta->modal_id ]->meta->process_load( $meta->as_array() );
}
}
return $modals;
}
}
if ( ! function_exists( 'get_current_modal' ) ) {
function get_current_modal( $key = null ) {
global $current_modal;
if ( ! $key ) {
return $current_modal;
} else {
$values = $current_modal->as_array();
return emresolve( $values, $key, false );
}
}
}
if ( ! function_exists( 'get_current_modal_id' ) ) {
function get_current_modal_id() {
global $current_modal;
return $current_modal ? $current_modal->id : null;
}
}
if ( ! function_exists( 'count_all_modals' ) ) {
function count_all_modals() {
global $wpdb;
return (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}em_modals WHERE is_trash = 0" );
}
}
if ( ! function_exists( 'count_deleted_modals' ) ) {
function count_deleted_modals() {
global $wpdb;
return (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}em_modals WHERE is_trash = 1" );
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* Importer for easy-modal model modal meta
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class EModal_Model_Modal_Meta extends EModal_Model {
protected $_class_name = 'EModal_Model_Modal_Meta';
protected $_table_name = 'em_modal_metas';
protected $_pk = 'modal_id';
protected $_default_fields = [
'id' => null,
'modal_id' => null,
'display' => [],
'close' => [],
];
public function __construct( $id = null ) {
global $wpdb;
$table_name = $wpdb->prefix . $this->_table_name;
$class_name = strtolower( $this->_class_name );
$this->_default_fields['modal_id'] = $id;
$this->_data = apply_filters( "{$class_name}_fields", $this->_default_fields );
if ( $id && is_numeric( $id ) ) {
$row = $wpdb->get_row( "SELECT * FROM $table_name WHERE modal_id = $id ORDER BY id DESC LIMIT 1", ARRAY_A );
if ( $row[ $this->_pk ] ) {
$this->process_load( $row );
}
} else {
$this->set_fields( apply_filters( "{$class_name}_defaults", [] ) );
}
return $this;
}
public function save() {
global $wpdb;
$table_name = $wpdb->prefix . $this->_table_name;
$rows = $wpdb->get_col( "SELECT id FROM $table_name WHERE modal_id = $this->modal_id ORDER BY id DESC" );
if ( count( $rows ) ) {
$this->id = $rows[0];
$wpdb->update( $table_name, $this->serialized_values(), [ 'id' => $this->id ] );
} else {
$wpdb->insert( $table_name, $this->serialized_values() );
$this->id = $wpdb->insert_id;
}
}
}

View File

@@ -0,0 +1,134 @@
<?php
/**
* Importer for easy-modal model theme
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class EModal_Model_Theme extends EModal_Model {
protected $_class_name = 'EModal_Model_Theme';
protected $_table_name = 'em_themes';
protected $meta;
protected $_default_fields = [
'id' => null,
'name' => 'Default',
'created' => '0000-00-00 00:00:00',
'modified' => '0000-00-00 00:00:00',
'is_system' => 0,
'is_trash' => 0,
];
public function __construct( $id = null ) {
parent::__construct( $id );
$this->load_meta();
return $this;
}
public function __get( $key ) {
if ( 'meta' === $key ) {
return $this->meta;
} else {
return parent::__get( $key );
}
}
public function save() {
if ( ! $this->id ) {
$this->created = date( 'Y-m-d H:i:s' );
}
$this->modified = date( 'Y-m-d H:i:s' );
parent::save();
$this->meta->theme_id = $this->id;
$this->meta->save();
}
public function load_meta() {
if ( empty( $this->meta ) ) {
$this->meta = new EModal_Model_Theme_Meta( $this->id );
}
return $this->meta;
}
public function as_array() {
$array = parent::as_array();
$array['meta'] = $this->meta->as_array();
return $array;
}
public function set_fields( array $data ) {
if ( ! empty( $data['meta'] ) ) {
$this->meta->set_fields( $data['meta'] );
unset( $data['meta'] );
}
parent::set_fields( $data );
}
}
if ( ! function_exists( 'get_all_modal_themes' ) ) {
function get_all_modal_themes( $where = 'is_trash != 1' ) {
global $wpdb;
$themes = [];
$theme_ids = [];
$EModal_Model_Theme = new EModal_Model_Theme();
$EModal_Model_Theme_Meta = new EModal_Model_Theme_Meta();
foreach ( $EModal_Model_Theme->load( "SELECT * FROM {$wpdb->prefix}em_themes" . ( $where ? ' WHERE ' . $where : '' ) ) as $theme ) {
$themes[ $theme->id ] = $theme;
$theme_ids[] = $theme->id;
}
if ( count( $themes ) ) {
foreach ( $EModal_Model_Theme_Meta->load( "SELECT * FROM {$wpdb->prefix}em_theme_metas WHERE theme_id IN (" . implode( ',', $theme_ids ) . ')' ) as $meta ) {
$themes[ $meta->theme_id ]->meta->process_load( $meta->as_array() );
}
}
return $themes;
}
}
if ( ! function_exists( 'get_current_modal_theme' ) ) {
function get_current_modal_theme( $key = null ) {
global $current_theme;
if ( ! $key ) {
return $current_theme;
} else {
$values = $current_theme->as_array();
return emresolve( $values, $key, false );
}
}
}
if ( ! function_exists( 'get_current_modal_theme_id' ) ) {
function get_current_modal_theme_id() {
global $current_theme;
return $current_theme->id;
}
}
if ( ! function_exists( 'count_all_modal_themes' ) ) {
function count_all_modal_themes() {
global $wpdb;
return (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}em_themes WHERE is_trash = 0" );
}
}
if ( ! function_exists( 'count_deleted_modal_themes' ) ) {
function count_deleted_modal_themes() {
global $wpdb;
return (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}em_themes WHERE is_trash = 1" );
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* Importer for easy-modal model theme meta
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class EModal_Model_Theme_Meta extends EModal_Model {
protected $_class_name = 'EModal_Model_Theme_Meta';
protected $_table_name = 'em_theme_metas';
protected $_pk = 'theme_id';
protected $_default_fields = [
'id' => null,
'theme_id' => null,
'overlay' => [],
'container' => [],
'close' => [],
'title' => [],
'content' => [],
];
public function __construct( $id = null ) {
global $wpdb;
$table_name = $wpdb->prefix . $this->_table_name;
$class_name = strtolower( $this->_class_name );
$this->_default_fields['theme_id'] = $id;
$this->_data = apply_filters( "{$class_name}_fields", $this->_default_fields );
if ( $id && is_numeric( $id ) ) {
$row = $wpdb->get_row( "SELECT * FROM $table_name WHERE theme_id = $id ORDER BY id DESC LIMIT 1", ARRAY_A );
if ( $row[ $this->_pk ] ) {
$this->process_load( $row );
}
} else {
$this->set_fields( apply_filters( "{$class_name}_defaults", [] ) );
}
return $this;
}
public function save() {
global $wpdb;
$table_name = $wpdb->prefix . $this->_table_name;
$rows = $wpdb->get_col( "SELECT id FROM $table_name WHERE theme_id = $this->theme_id ORDER BY id DESC" );
if ( count( $rows ) ) {
$this->id = $rows[0];
$wpdb->update( $table_name, $this->serialized_values(), [ 'id' => $this->id ] );
} else {
$wpdb->insert( $table_name, $this->serialized_values() );
$this->id = $wpdb->insert_id;
}
}
}