Add Creative Elements templates and update index files
- Introduced new templates for catalog, checkout, contact, and error pages. - Implemented caching headers and redirection in index.php files across various directories. - Enhanced product and layout templates for better integration with Creative Elements. - Added backoffice header styles and scripts for improved UI/UX in the admin panel.
This commit is contained in:
269
modules/creativeelements/core/common/app.php
Normal file
269
modules/creativeelements/core/common/app.php
Normal file
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
/**
|
||||
* Creative Elements - live Theme & Page Builder
|
||||
*
|
||||
* @author WebshopWorks, Elementor
|
||||
* @copyright 2019-2022 WebshopWorks.com & Elementor.com
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0.html
|
||||
*/
|
||||
|
||||
namespace CE;
|
||||
|
||||
defined('_PS_VERSION_') or die;
|
||||
|
||||
// use CE\CoreXCommonXModulesXFinderXModule as Finder;
|
||||
use CE\CoreXBaseXApp as BaseApp;
|
||||
use CE\CoreXCommonXModulesXAjaxXModule as Ajax;
|
||||
use CE\CoreXCommonXModulesXConnectXModule as Connect;
|
||||
|
||||
/**
|
||||
* App
|
||||
*
|
||||
* Elementor's common app that groups shared functionality, components and configuration
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class CoreXCommonXApp extends BaseApp
|
||||
{
|
||||
private $templates = [];
|
||||
|
||||
/**
|
||||
* App constructor.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @access public
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->addDefaultTemplates();
|
||||
|
||||
add_action('elementor/editor/before_enqueue_scripts', [$this, 'register_scripts']);
|
||||
// add_action('admin_enqueue_scripts', [$this, 'register_scripts']);
|
||||
add_action('wp_enqueue_scripts', [$this, 'register_scripts']);
|
||||
|
||||
add_action('elementor/editor/before_enqueue_styles', [$this, 'register_styles']);
|
||||
// add_action('admin_enqueue_scripts', [$this, 'register_styles']);
|
||||
add_action('wp_enqueue_scripts', [$this, 'register_styles'], 9);
|
||||
|
||||
add_action('elementor/editor/footer', [$this, 'print_templates']);
|
||||
// add_action('admin_footer', [$this, 'print_templates']);
|
||||
add_action('wp_footer', [$this, 'print_templates']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Init components
|
||||
*
|
||||
* Initializing common components.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @access public
|
||||
*/
|
||||
public function initComponents()
|
||||
{
|
||||
$this->addComponent('ajax', new Ajax());
|
||||
|
||||
// if (current_user_can('manage_options')) {
|
||||
// if (!is_customize_preview()) {
|
||||
// $this->addComponent('finder', new Finder());
|
||||
// }
|
||||
|
||||
// $this->addComponent('connect', new Connect());
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name.
|
||||
*
|
||||
* Retrieve the app name.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @access public
|
||||
*
|
||||
* @return string Common app name.
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'common';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register scripts.
|
||||
*
|
||||
* Register common scripts.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @access public
|
||||
*/
|
||||
public function registerScripts()
|
||||
{
|
||||
wp_register_script(
|
||||
'elementor-common-modules',
|
||||
$this->getJsAssetsUrl('common-modules'),
|
||||
[],
|
||||
_CE_VERSION_,
|
||||
true
|
||||
);
|
||||
|
||||
wp_register_script(
|
||||
'backbone-marionette',
|
||||
$this->getJsAssetsUrl('backbone.marionette', 'views/lib/backbone/'),
|
||||
[
|
||||
'backbone',
|
||||
],
|
||||
'2.4.5',
|
||||
true
|
||||
);
|
||||
|
||||
wp_register_script(
|
||||
'backbone-radio',
|
||||
$this->getJsAssetsUrl('backbone.radio', 'views/lib/backbone/'),
|
||||
[
|
||||
'backbone',
|
||||
],
|
||||
'1.0.4',
|
||||
true
|
||||
);
|
||||
|
||||
wp_register_script(
|
||||
'elementor-dialog',
|
||||
$this->getJsAssetsUrl('dialog', 'views/lib/dialog/'),
|
||||
[
|
||||
'jquery-ui-position',
|
||||
],
|
||||
'4.7.1',
|
||||
true
|
||||
);
|
||||
|
||||
wp_register_script(
|
||||
'elementor-common',
|
||||
$this->getJsAssetsUrl('common'),
|
||||
[
|
||||
'jquery',
|
||||
'jquery-ui-draggable',
|
||||
'backbone-marionette',
|
||||
'backbone-radio',
|
||||
'elementor-common-modules',
|
||||
'elementor-dialog',
|
||||
],
|
||||
_CE_VERSION_,
|
||||
true
|
||||
);
|
||||
|
||||
$this->printConfig();
|
||||
|
||||
wp_enqueue_script('elementor-common');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register styles.
|
||||
*
|
||||
* Register common styles.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @access public
|
||||
*/
|
||||
public function registerStyles()
|
||||
{
|
||||
wp_register_style(
|
||||
'elementor-icons',
|
||||
$this->getCssAssetsUrl('elementor-icons', 'views/lib/eicons/css/'),
|
||||
[],
|
||||
'4.3.1'
|
||||
);
|
||||
|
||||
wp_register_style(
|
||||
'ce-icons',
|
||||
$this->getCssAssetsUrl('ceicons', 'views/lib/ceicons/'),
|
||||
[],
|
||||
_CE_VERSION_
|
||||
);
|
||||
|
||||
wp_enqueue_style(
|
||||
'elementor-common',
|
||||
$this->getCssAssetsUrl('common', null, 'default', true),
|
||||
[
|
||||
'elementor-icons',
|
||||
],
|
||||
_CE_VERSION_
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add template.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $template Can be either a link to template file or template
|
||||
* HTML content.
|
||||
* @param string $type Optional. Whether to handle the template as path
|
||||
* or text. Default is `path`.
|
||||
*/
|
||||
public function addTemplate($template, $type = 'path')
|
||||
{
|
||||
if ('path' === $type) {
|
||||
ob_start();
|
||||
|
||||
include $template;
|
||||
|
||||
$template = ob_get_clean();
|
||||
}
|
||||
|
||||
$this->templates[] = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print Templates
|
||||
*
|
||||
* Prints all registered templates.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @access public
|
||||
*/
|
||||
public function printTemplates()
|
||||
{
|
||||
foreach ($this->templates as $template) {
|
||||
echo $template;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get init settings.
|
||||
*
|
||||
* Define the default/initial settings of the common app.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @access protected
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getInitSettings()
|
||||
{
|
||||
return [
|
||||
'version' => _CE_VERSION_,
|
||||
'isRTL' => is_rtl(),
|
||||
'activeModules' => array_keys($this->getComponents()),
|
||||
'urls' => [
|
||||
'assets' => _MODULE_DIR_ . 'creativeelements/views/',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add default templates.
|
||||
*
|
||||
* Register common app default templates.
|
||||
* @since 2.3.0
|
||||
* @access private
|
||||
*/
|
||||
private function addDefaultTemplates()
|
||||
{
|
||||
$default_templates = [
|
||||
'includes/editor-templates/library-layout.php',
|
||||
];
|
||||
|
||||
foreach ($default_templates as $template) {
|
||||
$this->addTemplate(_CE_PATH_ . $template);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
modules/creativeelements/core/common/index.php
Normal file
8
modules/creativeelements/core/common/index.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
header('Expires: Thu, 28 Feb 2019 00:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
header('Location: ../../../../');
|
||||
die;
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
header('Expires: Thu, 28 Feb 2019 00:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
header('Location: ../../../../../../');
|
||||
die;
|
||||
320
modules/creativeelements/core/common/modules/ajax/module.php
Normal file
320
modules/creativeelements/core/common/modules/ajax/module.php
Normal file
@@ -0,0 +1,320 @@
|
||||
<?php
|
||||
/**
|
||||
* Creative Elements - live Theme & Page Builder
|
||||
*
|
||||
* @author WebshopWorks, Elementor
|
||||
* @copyright 2019-2022 WebshopWorks.com & Elementor.com
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0.html
|
||||
*/
|
||||
|
||||
namespace CE;
|
||||
|
||||
defined('_PS_VERSION_') or die;
|
||||
|
||||
use CE\CoreXBaseXModule as BaseModule;
|
||||
use CE\CoreXUtilsXExceptions as Exceptions;
|
||||
|
||||
/**
|
||||
* Elementor ajax manager.
|
||||
*
|
||||
* Elementor ajax manager handler class is responsible for handling Elementor
|
||||
* ajax requests, ajax responses and registering actions applied on them.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class CoreXCommonXModulesXAjaxXModule extends BaseModule
|
||||
{
|
||||
const NONCE_KEY = 'elementor_ajax';
|
||||
|
||||
/**
|
||||
* Ajax actions.
|
||||
*
|
||||
* Holds all the register ajax action.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $ajax_actions = [];
|
||||
|
||||
/**
|
||||
* Ajax requests.
|
||||
*
|
||||
* Holds all the register ajax requests.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $requests = [];
|
||||
|
||||
/**
|
||||
* Ajax response data.
|
||||
*
|
||||
* Holds all the response data for all the ajax requests.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $response_data = [];
|
||||
|
||||
/**
|
||||
* Current ajax action ID.
|
||||
*
|
||||
* Holds all the ID for the current ajax action.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $current_action_id = null;
|
||||
|
||||
/**
|
||||
* Ajax manager constructor.
|
||||
*
|
||||
* Initializing Elementor ajax manager.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
add_action('wp_ajax_elementor_ajax', [$this, 'handle_ajax_request']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module name.
|
||||
*
|
||||
* Retrieve the module name.
|
||||
*
|
||||
* @since 1.7.0
|
||||
* @access public
|
||||
*
|
||||
* @return string Module name.
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'ajax';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register ajax action.
|
||||
*
|
||||
* Add new actions for a specific ajax request and the callback function to
|
||||
* be handle the response.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $tag Ajax request name/tag.
|
||||
* @param callable $callback The callback function.
|
||||
*/
|
||||
public function registerAjaxAction($tag, $callback)
|
||||
{
|
||||
if (!did_action('elementor/ajax/register_actions')) {
|
||||
_doing_it_wrong(__METHOD__, esc_html(sprintf('Use `%s` hook to register ajax action.', 'elementor/ajax/register_actions')), '2.0.0');
|
||||
}
|
||||
|
||||
if (is_array($callback) && isset($callback[1]) && strpos($callback[1], '_') !== false) {
|
||||
$callback[1] = \Tools::toCamelCase($callback[1]);
|
||||
}
|
||||
|
||||
$this->ajax_actions[$tag] = compact('tag', 'callback');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ajax request.
|
||||
*
|
||||
* Verify ajax nonce, and run all the registered actions for this request.
|
||||
*
|
||||
* Fired by `wp_ajax_elementor_ajax` action.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*/
|
||||
public function handleAjaxRequest()
|
||||
{
|
||||
if (!$this->verifyRequestNonce()) {
|
||||
$this->addResponseData(false, __('Token Expired.'))
|
||||
->sendError(Exceptions::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
$editor_post_id = 0;
|
||||
|
||||
if (!empty($_REQUEST['editor_post_id'])) {
|
||||
$editor_post_id = absint($_REQUEST['editor_post_id']);
|
||||
|
||||
Plugin::$instance->db->switchToPost($editor_post_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register ajax actions.
|
||||
*
|
||||
* Fires when an ajax request is received and verified.
|
||||
*
|
||||
* Used to register new ajax action handles.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param self $this An instance of ajax manager.
|
||||
*/
|
||||
do_action('elementor/ajax/register_actions', $this);
|
||||
|
||||
$this->requests = json_decode(${'_POST'}['actions'], true);
|
||||
|
||||
foreach ($this->requests as $id => $action_data) {
|
||||
$this->current_action_id = $id;
|
||||
|
||||
if (!isset($this->ajax_actions[$action_data['action']])) {
|
||||
$this->addResponseData(false, __('Action not found.'), Exceptions::BAD_REQUEST);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($editor_post_id) {
|
||||
$action_data['data']['editor_post_id'] = $editor_post_id;
|
||||
}
|
||||
|
||||
// try {
|
||||
$results = call_user_func($this->ajax_actions[$action_data['action']]['callback'], $action_data['data'], $this);
|
||||
|
||||
if (false === $results) {
|
||||
$this->addResponseData(false);
|
||||
} else {
|
||||
$this->addResponseData(true, $results);
|
||||
}
|
||||
// } catch (\Exception $e) {
|
||||
// $this->addResponseData(false, $e->getMessage(), $e->getCode());
|
||||
// }
|
||||
}
|
||||
|
||||
$this->current_action_id = null;
|
||||
|
||||
$this->sendSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current action data.
|
||||
*
|
||||
* Retrieve the data for the current ajax request.
|
||||
*
|
||||
* @since 2.0.1
|
||||
* @access public
|
||||
*
|
||||
* @return bool|mixed Ajax request data if action exist, False otherwise.
|
||||
*/
|
||||
public function getCurrentActionData()
|
||||
{
|
||||
if (!$this->current_action_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->requests[$this->current_action_id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create nonce.
|
||||
*
|
||||
* Creates a cryptographic token to
|
||||
* give the user an access to Elementor ajax actions.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @access public
|
||||
*
|
||||
* @return string The nonce token.
|
||||
*/
|
||||
public function createNonce()
|
||||
{
|
||||
return wp_create_nonce(self::NONCE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify request nonce.
|
||||
*
|
||||
* Whether the request nonce verified or not.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @access public
|
||||
*
|
||||
* @return bool True if request nonce verified, False otherwise.
|
||||
*/
|
||||
public function verifyRequestNonce()
|
||||
{
|
||||
return !empty($_REQUEST['_nonce']) && wp_verify_nonce($_REQUEST['_nonce'], self::NONCE_KEY);
|
||||
}
|
||||
|
||||
protected function getInitSettings()
|
||||
{
|
||||
return [
|
||||
'url' => Helper::getAjaxLink(),
|
||||
'nonce' => $this->createNonce(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax success response.
|
||||
*
|
||||
* Send a JSON response data back to the ajax request, indicating success.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access private
|
||||
*/
|
||||
private function sendSuccess()
|
||||
{
|
||||
$response = [
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'responses' => $this->response_data,
|
||||
],
|
||||
];
|
||||
|
||||
die(str_replace('}},"', "}},\n\"", json_encode($response)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax failure response.
|
||||
*
|
||||
* Send a JSON response data back to the ajax request, indicating failure.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access private
|
||||
*
|
||||
* @param null $code
|
||||
*/
|
||||
private function sendError($code = null)
|
||||
{
|
||||
wp_send_json_error([
|
||||
'responses' => $this->response_data,
|
||||
], $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add response data.
|
||||
*
|
||||
* Add new response data to the array of all the ajax requests.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access private
|
||||
*
|
||||
* @param bool $success True if the requests returned successfully, False otherwise.
|
||||
* @param mixed $data Optional. Response data. Default is null.
|
||||
* @param int $code Optional. Response code. Default is 200.
|
||||
*
|
||||
* @return Module An instance of ajax manager.
|
||||
*/
|
||||
private function addResponseData($success, $data = null, $code = 200)
|
||||
{
|
||||
$this->response_data[$this->current_action_id] = [
|
||||
'success' => $success,
|
||||
'code' => $code,
|
||||
'data' => $data,
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
8
modules/creativeelements/core/common/modules/index.php
Normal file
8
modules/creativeelements/core/common/modules/index.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
header('Expires: Thu, 28 Feb 2019 00:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
header('Location: ../../../../../');
|
||||
die;
|
||||
Reference in New Issue
Block a user