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,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;
}
}
}