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:
2025-07-01 00:56:07 +02:00
parent f00cd5b992
commit 6cc26c0ed2
642 changed files with 213294 additions and 12 deletions

View File

@@ -0,0 +1,52 @@
<?php
/**
* Creative Elements - live Theme & Page Builder
*
* @author WebshopWorks
* @copyright 2019-2022 WebshopWorks.com
* @license One domain support license
*/
namespace CE;
defined('_PS_VERSION_') or die;
class WPError
{
private $code;
private $message;
public function __construct($code = '', $message = '', $data = '')
{
if (!$code) {
return;
}
if ($data) {
throw new \RuntimeException('todo');
}
$this->code = $code;
$this->message = $message;
}
public function getErrorMessage($code = '')
{
if (!$this->code) {
return '';
}
if ($code) {
throw new \RuntimeException('todo');
}
return $this->code . ($this->message ? " - {$this->message}" : '');
}
}
function is_wp_error($error)
{
return $error instanceof WPError;
}
function _doing_it_wrong($function, $message = '', $version = '')
{
die(\Tools::displayError($function . ' was called incorrectly. ' . $message . ' ' . $version));
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,625 @@
<?php
/**
* Creative Elements - live Theme & Page Builder
*
* @author WebshopWorks
* @copyright 2019-2022 WebshopWorks.com
* @license One domain support license
*/
namespace CE;
defined('_PS_VERSION_') or die;
class WPPost
{
private $id;
private $uid;
private $model;
public $_obj;
public $post_author = 0;
public $post_parent = 0;
public $post_date = '';
public $post_modified = '';
public $post_title = '';
public $post_excerpt = '';
public $post_content = '';
public $template_type = 'post';
private function __construct()
{
}
public function __get($prop)
{
switch ($prop) {
case 'uid':
$val = $this->uid;
break;
case 'ID':
case 'post_ID':
$val = $this->id;
break;
case 'post_type':
$val = $this->model;
break;
case 'post_status':
$active = property_exists($this->_obj, 'active') ? 'active' : (
property_exists($this->_obj, 'enabled') ? 'enabled' : 'actif'
);
$val = $this->_obj->$active ? 'publish' : 'private';
break;
default:
throw new \RuntimeException('Unknown property: ' . $prop);
}
return $val;
}
public function __set($prop, $val)
{
switch ($prop) {
case 'ID':
case 'post_ID':
// allow change only when starts with zero
empty($this->id[0]) && $this->id = "$val";
break;
case 'post_type':
// readonly
break;
case 'post_status':
$active = property_exists($this->_obj, 'active') ? 'active' : 'actif';
$this->_obj->$active = 'publish' == $val;
break;
default:
throw new \RuntimeException('Unknown property: ' . $prop);
}
}
public function getLangId()
{
return (int) \Tools::substr($this->id, -4, 2);
}
public static function getInstance(UId $uid, array &$postarr = null)
{
$self = new self();
$self->id = "$uid";
$self->uid = $uid;
$self->model = $uid->getModel();
$objectModel = '\\' . $self->model;
if ($postarr) {
$obj = (object) $postarr;
} elseif ($uid->id_type <= UId::TEMPLATE) {
$obj = new $objectModel($uid->id ? $uid->id : null);
} elseif ($uid->id_type === UId::PRODUCT) {
$obj = new \Product($uid->id, false, $uid->id_lang, $uid->id_shop);
} else {
$obj = new $objectModel($uid->id, $uid->id_lang, $uid->id_shop);
}
$self->_obj = $obj;
if (in_array($uid->id_type, [UId::REVISION, UId::TEMPLATE, UId::THEME])) {
$self->template_type = &$obj->type;
} elseif ($uid->id_type === UId::CONTENT) {
$self->template_type = 'content';
}
property_exists($obj, 'id_employee') && $self->post_author = &$obj->id_employee;
property_exists($obj, 'parent') && $self->post_parent = &$obj->parent;
property_exists($obj, 'date_add') && $self->post_date = &$obj->date_add;
property_exists($obj, 'date_upd') && $self->post_modified = &$obj->date_upd;
if (property_exists($obj, 'title')) {
$self->post_title = &$obj->title;
} elseif (property_exists($obj, 'name')) {
$self->post_title = &$obj->name;
} elseif (property_exists($obj, 'meta_title')) {
$self->post_title = &$obj->meta_title;
}
if (property_exists($obj, 'content')) {
$self->post_content = &$obj->content;
} elseif (property_exists($obj, 'description')) {
$self->post_content = &$obj->description;
} elseif (property_exists($obj, 'post_content')) {
$self->post_content = &$obj->post_content;
}
return $self;
}
}
function get_post($post = null, $output = 'OBJECT', $filter = 'raw')
{
if (null === $post || 0 === $post) {
$post = get_the_ID();
}
if (false === $post || $post instanceof WPPost) {
$_post = $post;
} elseif ($post instanceof UId) {
$_post = WPPost::getInstance($post);
} elseif (is_numeric($post)) {
$_post = WPPost::getInstance(UId::parse($post));
} else {
_doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, 'Invalid $post argument!');
}
if (!$_post) {
return null;
}
if ('OBJECT' !== $output || 'raw' !== $filter) {
throw new \RuntimeException('todo');
}
return $_post;
}
function get_post_status($post = null)
{
if ($_post = get_post($post)) {
return $_post->post_status;
}
return false;
}
function wp_update_post($postarr = [], $wp_error = false)
{
if (is_array($postarr)) {
$id_key = isset($postarr['ID']) ? 'ID' : 'post_ID';
if (empty($postarr[$id_key])) {
_doing_it_wrong(__FUNCTION__, 'ID is missing!');
}
$post = get_post($postarr[$id_key]);
foreach ($postarr as $key => $value) {
$post->$key = $value;
}
} elseif ($postarr instanceof WPPost) {
$post = $postarr;
}
if (!isset($post) || $wp_error) {
throw new \RuntimeException('TODO');
}
// Fix for required lang properties must be defined on default language
$id_lang_def = \Configuration::get('PS_LANG_DEFAULT');
\Configuration::set('PS_LANG_DEFAULT', $post->uid->id_lang);
try {
// Fix: category groups would lose after save
if ($post->_obj instanceof \Category) {
$post->_obj->groupBox = $post->_obj->getGroups();
}
$res = @$post->_obj->update();
} catch (\Exception $ex) {
$res = false;
}
\Configuration::set('PS_LANG_DEFAULT', $id_lang_def);
return $res ? $post->ID : 0;
}
function wp_insert_post(array $postarr, $wp_error = false)
{
$is_revision = 'CERevision' === $postarr['post_type'];
if ($wp_error || !$is_revision && 'CETemplate' != $postarr['post_type']) {
throw new \RuntimeException('TODO');
}
$uid = new UId(0, $is_revision ? UId::REVISION : UId::TEMPLATE);
$post = WPPost::getInstance($uid);
$postarr['post_author'] = \Context::getContext()->employee->id;
foreach ($postarr as $key => &$value) {
$post->$key = $value;
}
if ($post->_obj->add()) {
$uid->id = $post->_obj->id;
$post->ID = "$uid";
} else {
$post->ID = 0;
}
return $post->ID;
}
function wp_delete_post($postid, $force_delete = false)
{
$post = get_post($postid);
return $post->_obj->delete() || $force_delete ? $post : false;
}
function get_post_meta($id, $key = '', $single = false)
{
if (false === $id) {
return $id;
}
$table = _DB_PREFIX_ . 'ce_meta';
$id = ($uid = UId::parse($id)) ? $uid->toDefault() : preg_replace('/\D+/', '', $id);
if (!is_numeric($id)) {
_doing_it_wrong(__FUNCTION__, 'Id must be numeric!');
}
if (!$key) {
$res = [];
$rows = \Db::getInstance()->executeS("SELECT name, value FROM $table WHERE id = $id");
if (!empty($rows)) {
foreach ($rows as &$row) {
$key = &$row['name'];
$val = &$row['value'];
isset($res[$key]) or $res[$key] = [];
$res[$key][] = isset($val[0]) && ('{' == $val[0] || '[' == $val[0] || '"' == $val[0]) ? json_decode($val, true) : $val;
}
}
return $res;
}
$key = preg_replace('/\W+/', '', $key);
if (!$single) {
throw new \RuntimeException('TODO');
}
$val = \Db::getInstance()->getValue("SELECT value FROM $table WHERE id = $id AND name = '$key'");
return isset($val[0]) && ('{' == $val[0] || '[' == $val[0] || '"' == $val[0]) ? json_decode($val, true) : $val;
}
function update_post_meta($id, $key, $value, $prev_value = '')
{
if ($prev_value) {
throw new \RuntimeException('TODO');
}
$db = \Db::getInstance();
$table = _DB_PREFIX_ . 'ce_meta';
$res = true;
$ids = ($uid = UId::parse($id)) ? $uid->getListByShopContext() : (array) $id;
$data = [
'name' => preg_replace('/\W+/', '', $key),
'value' => $db->escape(is_array($value) || is_object($value) ? json_encode($value) : $value, true),
];
foreach ($ids as $id) {
$data['id'] = preg_replace('/\D+/', '', $id);
$id_ce_meta = $db->getValue("SELECT id_ce_meta FROM $table WHERE id = {$data['id']} AND name = '{$data['name']}'");
if ($id_ce_meta) {
$data['id_ce_meta'] = (int) $id_ce_meta;
$type = \Db::REPLACE;
} else {
unset($data['id_ce_meta']);
$type = \Db::INSERT;
}
$res &= $db->insert($table, $data, false, true, $type, false);
}
return $res;
}
function delete_post_meta($id, $key, $value = '')
{
if ($value) {
throw new \RuntimeException('TODO');
}
$ids = ($uid = UId::parse($id)) ? $uid->getListByShopContext() : (array) $id;
foreach ($ids as &$id) {
$id = preg_replace('/\D+/', '', $id);
}
if (count($ids) > 1) {
$in = 'IN';
$ids = '(' . implode(', ', $ids) . ')';
} else {
$in = '=';
$ids = $ids[0];
}
$key = preg_replace('/[^\w\%]+/', '', $key);
$like = strrpos($key, '%') === false ? '=' : 'LIKE';
return \Db::getInstance()->delete('ce_meta', "id $in $ids AND name $like '$key'");
}
function get_post_type($post = null)
{
$uid = uidval($post, null);
return $uid ? $uid->getModel() : false;
}
function get_post_type_object($post_type)
{
// todo
return !$post_type ? null : (object) [
'cap' => (object) [
'edit_post' => 'edit',
'edit_posts' => 'edit',
'publish_posts' => 'edit',
],
];
}
function current_user_can($capability, $args = null)
{
if (is_admin()) {
$employee = \Context::getContext()->employee;
} elseif ($id_employee = get_current_user_id()) {
$employee = new \Employee($id_employee);
}
if (empty($employee->id_profile)) {
return false;
}
if ('manage_options' === $capability) {
return true;
}
if ($uid = uidval($args, false)) {
$controller = $uid->getAdminController();
} elseif (stripos($args, 'Admin') === 0) {
$controller = $args;
} else {
return false;
}
if ('AdminModules' === $controller) {
$id_module = \Module::getModuleIdByName($uid->getModule());
$action = 'view' === $capability ?: 'configure';
$result = \Module::getPermissionStatic($id_module, $action, $employee);
} else {
$id_tab = \Tab::getIdFromClassName($controller);
$access = \Profile::getProfileAccess($employee->id_profile, $id_tab);
$result = '1' === $access[$capability];
}
return $result;
}
function wp_set_post_lock($post_id)
{
if (!$user_id = get_current_user_id()) {
return false;
}
$now = time();
update_post_meta($post_id, '_edit_lock', "$now:$user_id");
return [$now, $user_id];
}
function wp_check_post_lock($post_id)
{
if (!$lock = get_post_meta($post_id, '_edit_lock', true)) {
return false;
}
list($time, $user) = explode(':', $lock);
if (empty($user)) {
return false;
}
$time_window = apply_filters('wp_check_post_lock_window', 150);
if ($time && $time > time() - $time_window && $user != get_current_user_id()) {
return (int) $user;
}
return false;
}
function wp_create_post_autosave(array $post_data)
{
$post_id = isset($post_data['ID']) ? $post_data['ID'] : $post_data['post_ID'];
unset($post_data['ID'], $post_data['post_ID']);
// Autosave already deleted in saveEditor method
$autosave = wp_get_post_autosave($post_id, get_current_user_id());
if ($autosave) {
foreach ($post_data as $key => $value) {
$autosave->$key = $value;
}
return $autosave->_obj->update() ? $autosave->ID : 0;
}
$post_data['post_type'] = 'CERevision';
$post_data['post_status'] = 'private';
$post_data['post_parent'] = $post_id;
$autosave_id = wp_insert_post($post_data);
if ($autosave_id) {
do_action('_wp_put_post_revision', $autosave_id);
return $autosave_id;
}
return 0;
}
function wp_is_post_autosave($post)
{
$uid = uidval($post);
if (UId::REVISION !== $uid->id_type) {
return false;
}
$table = _DB_PREFIX_ . 'ce_revision';
return \Db::getInstance()->getValue(
"SELECT parent FROM $table WHERE id_ce_revision = {$uid->id} AND active = 0"
);
}
function wp_get_post_autosave($post_id, $user_id = 0)
{
$uid = uidval($post_id);
if (UId::REVISION === $uid->id_type) {
return false;
}
$table = _DB_PREFIX_ . 'ce_revision';
$parent = $uid->toDefault();
$id_employee = (int) ($user_id ? $user_id : get_current_user_id());
$id = \Db::getInstance()->getValue(
"SELECT id_ce_revision FROM $table WHERE parent = $parent AND active = 0 AND id_employee = $id_employee"
);
return $id ? WPPost::getInstance(new UId($id, UId::REVISION)) : false;
}
function wp_get_post_parent_id($post_id)
{
if (!$post = get_post($post_id)) {
return false;
}
return !empty($post->_obj->parent) ? $post->_obj->parent : 0;
}
function wp_get_post_revisions($post_id, $args = null)
{
$uid = uidval($post_id);
$parent = $uid->toDefault();
$revisions = [];
$table = _DB_PREFIX_ . 'ce_revision';
$fields = !empty($args['fields']) && 'ids' === $args['fields'] ? 'id_ce_revision' : '*';
$id_employee = (int) \Context::getContext()->employee->id;
$limit = !empty($args['posts_per_page']) ? 'LIMIT 1, ' . (int) $args['posts_per_page'] : '';
$rows = \Db::getInstance()->executeS(
"SELECT $fields FROM $table
WHERE parent = $parent AND (active = 1 OR id_employee = $id_employee)
ORDER BY date_upd DESC $limit"
);
if ($rows) {
foreach ($rows as &$row) {
$uid = new UId($row['id_ce_revision'], UId::REVISION);
if ('*' === $fields) {
$row['id'] = $row['id_ce_revision'];
$revisions[] = WPPost::getInstance($uid, $row);
} else {
$revisions[] = "$uid";
}
}
}
return $revisions;
}
function wp_is_post_revision($post)
{
$revision = get_post($post);
return !empty($revision->_obj->parent) ? $revision->_obj->parent : false;
}
function wp_save_post_revision(WPPost $post)
{
if (UId::REVISION === $post->uid->id_type) {
return;
}
$revisions_to_keep = (int) \Configuration::get('elementor_max_revisions');
if (!$revisions_to_keep) {
return;
}
$db = \Db::getInstance();
$table = _DB_PREFIX_ . 'ce_revision';
$id_employee = \Context::getContext()->employee->id;
foreach (array_reverse($post->uid->getListByShopContext(true)) as $parent) {
$revisions = $db->executeS(
"SELECT id_ce_revision AS id FROM $table WHERE parent = $parent AND active = 1 ORDER BY date_upd DESC"
);
$return = wp_insert_post([
'post_type' => 'CERevision',
'post_status' => 'publish',
'post_author' => $id_employee,
'post_parent' => "$parent",
'post_title' => $post->post_title,
'post_content' => $post->post_content,
'template_type' => $post->template_type,
]);
if (!$return) {
$return = 0;
continue;
}
do_action('_wp_put_post_revision', $return);
for ($i = $revisions_to_keep - 1; isset($revisions[$i]); $i++) {
wp_delete_post_revision(new UId($revisions[$i]['id'], UId::REVISION));
}
}
return $return;
}
function wp_delete_post_revision($revision_id)
{
$revision = get_post($revision_id);
if ('CERevision' !== $revision->post_type) {
return false;
}
return $revision->_obj->delete();
}
function get_post_statuses()
{
return [
'private' => __('Disabled'),
'publish' => __('Enabled'),
];
}
function get_page_templates(WPPost $post = null, $post_type = 'CMS')
{
$templates = [];
foreach (\Context::getContext()->shop->theme->get('meta.available_layouts') as $name => &$layout) {
$templates[$name] = 'layout-full-width' === $name ? __('One Column') : $layout['name'];
}
$post_type = $post ? $post->post_type : $post_type;
if ('Product' === $post_type && \Configuration::get('CE_PRODUCT')) {
$templates = [];
}
return apply_filters("theme_{$post_type}_templates", $templates, $post);
}
function current_theme_supports()
{
// todo
return false;
}
function get_post_types_by_support($feature, $operator = 'and')
{
if ('elementor' !== $feature || 'and' !== $operator) {
throw new \RuntimeException('TODO');
}
return [
'CETemplate',
'CETheme',
'CMS',
'CMSCategory',
];
}
function post_type_supports($post_type, $feature)
{
if ('elementor' === $feature) {
return true;
}
if ('excerpt' === $feature) {
return false;
}
throw new \RuntimeException('TODO: ' . $feature);
}
function post_type_exists($post_type)
{
return UId::getTypeId($post_type) >= 0 ? true : false;
}
function setup_postdata($uid)
{
UId::$_ID = uidval($uid);
}

View File

@@ -0,0 +1,574 @@
<?php
/**
* Creative Elements - live Theme & Page Builder
*
* @author WebshopWorks
* @copyright 2019-2022 WebshopWorks.com
* @license One domain support license
*/
namespace CE;
defined('_PS_VERSION_') or die;
/**
* Unique Identifier
*/
class UId
{
const REVISION = 0;
const TEMPLATE = 1;
const CONTENT = 2;
const PRODUCT = 3;
const CATEGORY = 4;
const MANUFACTURER = 5;
const SUPPLIER = 6;
const CMS = 7;
const CMS_CATEGORY = 8;
const YBC_BLOG_POST = 9;
const XIPBLOG_POST = 10;
const STBLOG_POST = 11;
const ADVANCEBLOG_POST = 12;
const PRESTABLOG_POST = 13;
/** @deprecated */
const SIMPLEBLOG_POST = 14;
const PSBLOG_POST = 15;
const HIBLOG_POST = 16;
const THEME = 17;
const TVCMSBLOG_POST = 18;
public $id;
public $id_type;
public $id_lang;
public $id_shop;
private static $models = [
'CERevision',
'CETemplate',
'CEContent',
'Product',
'Category',
'Manufacturer',
'Supplier',
'CMS',
'CMSCategory',
'Ybc_blog_post_class',
'XipPostsClass',
'StBlogClass',
'BlogPosts',
'NewsClass',
'SimpleBlogPost',
'PsBlogBlog',
'HiBlogPost',
'CETheme',
'TvcmsPostsClass',
];
private static $admins = [
'AdminCEEditor',
'AdminCETemplates',
'AdminCEContent',
'AdminProducts',
'AdminCategories',
'AdminManufacturers',
'AdminSuppliers',
'AdminCmsContent',
'AdminCmsContent',
'AdminModules',
'AdminXipPost',
'AdminStBlog',
'AdminBlogPosts',
'AdminModules',
'AdminSimpleBlogPosts',
'AdminPsblogBlogs',
'AdminModules',
'AdminCEThemes',
'AdminTvcmsPost',
];
private static $modules = [
self::YBC_BLOG_POST => 'ybc_blog',
self::XIPBLOG_POST => 'xipblog',
self::STBLOG_POST => 'stblog',
self::ADVANCEBLOG_POST => 'advanceblog',
self::PRESTABLOG_POST => 'prestablog',
self::SIMPLEBLOG_POST => 'ph_simpleblog',
self::PSBLOG_POST => 'psblog',
self::HIBLOG_POST => 'hiblog',
self::TVCMSBLOG_POST => 'tvcmsblog',
];
private static $shop_ids = [];
public static $_ID;
public function __construct($id, $id_type, $id_lang = null, $id_shop = null)
{
$this->id = abs((int) $id);
$this->id_type = abs($id_type % 100);
if ($this->id_type <= self::TEMPLATE) {
$this->id_lang = 0;
$this->id_shop = 0;
} else {
is_null($id_lang) && $id_lang = \Context::getContext()->language->id;
$this->id_lang = abs($id_lang % 100);
$this->id_shop = $id_shop ? abs($id_shop % 100) : 0;
}
}
public function getModel()
{
if (empty(self::$models[$this->id_type])) {
throw new \RuntimeException('Unknown ObjectModel');
}
return self::$models[$this->id_type];
}
public function getAdminController()
{
if (empty(self::$admins[$this->id_type])) {
throw new \RuntimeException('Unknown AdminController');
}
if ((int) \Tools::getValue('footerProduct')) {
return self::$admins[self::PRODUCT];
}
return self::$admins[$this->id_type];
}
public function getModule()
{
return isset(self::$modules[$this->id_type]) ? self::$modules[$this->id_type] : '';
}
/**
* Get shop ID list where the object is allowed
*
* @param bool $all Get all or just by shop context
*
* @return array
*/
public function getShopIdList($all = false)
{
if ($this->id_type <= self::TEMPLATE) {
return [0];
}
if (isset(self::$shop_ids[$this->id_type][$this->id])) {
return self::$shop_ids[$this->id_type][$this->id];
}
isset(self::$shop_ids[$this->id_type]) or self::$shop_ids[$this->id_type] = [];
$ids = [];
$model = $this->getModel();
$def = &$model::${'definition'};
$db = \Db::getInstance();
$table = $db->escape(_DB_PREFIX_ . $def['table'] . '_shop');
$primary = $db->escape($def['primary']);
$id = (int) $this->id;
$ctx_ids = implode(', ', $all ? \Shop::getShops(true, null, true) : \Shop::getContextListShopID());
$rows = $db->executeS(
"SELECT id_shop FROM $table WHERE $primary = $id AND id_shop IN ($ctx_ids)"
);
if ($rows) {
foreach ($rows as &$row) {
$ids[] = $row['id_shop'];
}
}
return self::$shop_ids[$this->id_type][$this->id] = $ids;
}
public function getDefaultShopId()
{
return ($ids = $this->getShopIdList()) ? $ids[0] : 0;
}
/**
* Get UId list by shop context
*
* @param bool $strict Collect only from allowed shops
*
* @return array
*/
public function getListByShopContext($strict = false)
{
if ($this->id_shop || $this->id_type <= self::TEMPLATE) {
return ["$this"];
}
$list = [];
$ids = $strict ? $this->getShopIdList() : \Shop::getContextListShopID();
foreach ($ids as $id_shop) {
$this->id_shop = $id_shop;
$list[] = "$this";
}
$this->id_shop = 0;
return $list;
}
/**
* Get Language ID list of CE built contents
*
* @return array
*/
public function getBuiltLangIdList()
{
$ids = [];
if (self::TEMPLATE === $this->id_type) {
$ids[] = 0;
} elseif (self::CONTENT === $this->id_type || self::THEME === $this->id_type) {
foreach (\Language::getLanguages(false) as $lang) {
$ids[] = (int) $lang['id_lang'];
}
} else {
$id_shop = $this->id_shop ?: $this->getDefaultShopId();
$uids = self::getBuiltList($this->id, $this->id_type, $id_shop);
empty($uids[$id_shop]) or $ids = array_keys($uids[$id_shop]);
}
return $ids;
}
public function toDefault()
{
$id_shop = $this->id_shop ?: $this->getDefaultShopId();
return sprintf('%d%02d%02d%02d', $this->id, $this->id_type, $this->id_lang, $id_shop);
}
public function __toString()
{
return sprintf('%d%02d%02d%02d', $this->id, $this->id_type, $this->id_lang, $this->id_shop);
}
public static function parse($id)
{
if ($id instanceof UId) {
return $id;
}
if (!is_numeric($id) || \Tools::strlen($id) <= 6) {
return false;
}
return new self(
\Tools::substr($id, 0, -6),
\Tools::substr($id, -6, 2),
\Tools::substr($id, -4, 2),
\Tools::substr($id, -2)
);
}
public static function getTypeId($model)
{
$model = \Tools::strtolower($model);
return 'cms_category' === $model
? self::CMS_CATEGORY
: array_search($model, array_map('strtolower', self::$models))
;
}
/**
* Get UId list of CE built contents grouped by shop(s)
*
* @param int $id
* @param int $id_type
* @param int|null $id_shop
*
* @return array [
* id_shop => [
* id_lang => UId,
* ],
* ]
*/
public static function getBuiltList($id, $id_type, $id_shop = null)
{
$uids = [];
$table = _DB_PREFIX_ . 'ce_meta';
$shop = null === $id_shop ? '__' : '%02d';
$__id = sprintf("%d%02d__$shop", $id, $id_type, $id_shop);
$rows = \Db::getInstance()->executeS(
"SELECT id FROM $table WHERE id LIKE '$__id' AND name = '_elementor_edit_mode'"
);
if ($rows) {
foreach ($rows as &$row) {
$uid = self::parse($row['id']);
isset($uids[$uid->id_shop]) or $uids[$uid->id_shop] = [];
$uids[$uid->id_shop][$uid->id_lang] = $uid;
}
}
return $uids;
}
}
function absint($num)
{
if ($num instanceof UId) {
return $num;
}
$absint = preg_replace('/\D+/', '', $num);
return $absint ?: 0;
}
function get_user_meta($user_id, $key = '', $single = false)
{
return get_post_meta($user_id, '_u_' . $key, $single);
}
function update_user_meta($user_id, $key, $value, $prev_value = '')
{
return update_post_meta($user_id, '_u_' . $key, $value, $prev_value);
}
function get_the_ID()
{
if (!UId::$_ID && $uid_preview = \CreativeElements::getPreviewUId(false)) {
UId::$_ID = $uid_preview;
}
if (UId::$_ID) {
return UId::$_ID;
}
$controller = \Context::getContext()->controller;
if ($controller instanceof \AdminCEEditorController ||
$controller instanceof \CreativeElementsPreviewModuleFrontController
) {
$id_key = \Tools::getIsset('editor_post_id') ? 'editor_post_id' : 'template_id';
return UId::parse(\Tools::getValue('uid', \Tools::getValue($id_key)));
}
return false;
}
function get_preview_post_link($post = null, array $args = [], $relative = true)
{
$uid = uidval($post);
$ctx = \Context::getContext();
$id_shop = $uid->id_shop ?: $uid->getDefaultShopId();
$args['id_employee'] = $ctx->employee->id;
$args['adtoken'] = \Tools::getAdminTokenLite($uid->getAdminController());
$args['preview_id'] = $uid->toDefault();
switch ($uid->id_type) {
case UId::REVISION:
throw new \RuntimeException('TODO');
case UId::TEMPLATE:
$type = \CETemplate::getTypeById($uid->id);
$id_shop = $ctx->shop->id;
// continue
case UId::THEME:
isset($type) or $type = \CETheme::getTypeById($uid->id);
$id_lang = $uid->id_lang ?: $ctx->language->id;
if ('product' === $type || 'product-quick-view' === $type || 'product-miniature' === $type) {
$document = Plugin::$instance->documents->getDocOrAutoSave($uid, get_current_user_id());
$settings = $document->getData('settings');
empty($settings['preview_id']) or $prod = new \Product($settings['preview_id'], false, $id_lang);
if (empty($prod->id)) {
$prods = \Product::getProducts($id_lang, 0, 1, 'date_upd', 'DESC', false, true);
$prod = new \Product(!empty($prods[0]['id_product']) ? $prods[0]['id_product'] : null, false, $id_lang);
}
$prod_attr = empty($prod->cache_default_attribute) ? 0 : $prod->cache_default_attribute;
empty($prod->active) && empty($args['preview']) && $args['preview'] = 1;
$link = $ctx->link->getProductLink($prod, null, null, null, $id_lang, $id_shop, $prod_attr, false, $relative);
} elseif ('page-contact' === $type) {
$link = $ctx->link->getPageLink('contact', null, $id_lang, null, false, $id_shop, $relative);
} elseif ('page-not-found' === $type) {
$link = $ctx->link->getPageLink('pagenotfound', null, $id_lang, null, false, $id_shop, $relative);
} elseif ('page-index' === $type || 'header' === $type || 'footer' === $type) {
$link = $ctx->link->getPageLink('index', null, $id_lang, null, false, $id_shop, $relative);
\Configuration::get('PS_REWRITING_SETTINGS') && $link = preg_replace('~[^/]+$~', '', $link);
} else {
$link = $ctx->link->getModuleLink('creativeelements', 'preview', [], null, null, null, $relative);
}
break;
case UId::CONTENT:
$hook = \Tools::strtolower(\CEContent::getHookById($uid->id));
if (in_array($hook, Helper::$productHooks)) {
if ($id_product = (int) \Tools::getValue('footerProduct')) {
$args['footerProduct'] = $id_product;
$prod = new \Product($id_product, false, $uid->id_lang, $id_shop);
} else {
$prods = \Product::getProducts($uid->id_lang, 0, 1, 'date_upd', 'DESC', false, true);
$prod = new \Product(!empty($prods[0]['id_product']) ? $prods[0]['id_product'] : null, false, $uid->id_lang);
}
$prod_attr = empty($prod->cache_default_attribute) ? 0 : $prod->cache_default_attribute;
empty($prod->active) && empty($args['preview']) && $args['preview'] = 1;
$link = $ctx->link->getProductLink($prod, null, null, null, $uid->id_lang, $id_shop, $prod_attr, false, $relative);
break;
}
$page = 'index';
if (stripos($hook, 'shoppingcart') !== false) {
$page = 'cart';
$args['action'] = 'show';
} elseif ('displayleftcolumn' === $hook || 'displayrightcolumn' === $hook) {
$layout = 'r' != $hook[7] ? 'layout-left-column' : 'layout-right-column';
$layouts = $ctx->shop->theme->get('theme_settings')['layouts'];
unset($layouts['category']);
if ($key = array_search($layout, $layouts)) {
$page = $key;
} elseif ($key = array_search('layout-both-columns', $layouts)) {
$page = $key;
}
} elseif ('displaynotfound' === $hook) {
$page = 'search';
} elseif ('displaymaintenance' === $hook) {
$args['maintenance'] = 1;
}
$link = $ctx->link->getPageLink($page, null, $uid->id_lang, null, false, $id_shop, $relative);
if ('index' === $page && \Configuration::get('PS_REWRITING_SETTINGS')) {
// Remove rewritten URL if exists
$link = preg_replace('~[^/]+$~', '', $link);
}
break;
case UId::PRODUCT:
$prod = new \Product($uid->id, false, $uid->id_lang, $id_shop);
$prod_attr = !empty($prod->cache_default_attribute) ? $prod->cache_default_attribute : 0;
empty($prod->active) && empty($args['preview']) && $args['preview'] = 1;
$link = $ctx->link->getProductLink($prod, null, null, null, $uid->id_lang, $id_shop, $prod_attr, false, $relative);
break;
case UId::CATEGORY:
$link = $ctx->link->getCategoryLink($uid->id, null, $uid->id_lang, null, $id_shop, $relative);
break;
case UId::CMS:
$link = $ctx->link->getCmsLink($uid->id, null, null, $uid->id_lang, $id_shop, $relative);
break;
case UId::YBC_BLOG_POST:
$link = \Module::getInstanceByName('ybc_blog')->getLink('blog', ['id_post' => $uid->id], $uid->id_lang);
break;
case UID::XIPBLOG_POST:
$link = call_user_func('XipBlog::xipBlogPostLink', ['id' => $uid->id]);
break;
case UId::STBLOG_POST:
$post = new \StBlogClass($uid->id, $uid->id_lang);
$link = $ctx->link->getModuleLink('stblog', 'article', [
'id_st_blog' => $uid->id,
'id_blog' => $uid->id,
'rewrite' => $post->link_rewrite,
], null, $uid->id_lang, null, $relative);
break;
case UId::ADVANCEBLOG_POST:
$post = new \BlogPosts($uid->id, $uid->id_lang);
$args['blogtoken'] = $args['adtoken'];
unset($args['adtoken']);
$link = $ctx->link->getModuleLink('advanceblog', 'detail', [
'id' => $uid->id,
'post' => $post->link_rewrite,
], null, $uid->id_lang, null, $relative);
break;
case UId::PRESTABLOG_POST:
$post = new \NewsClass($uid->id, $uid->id_lang);
empty($post->actif) && $args['preview'] = \Module::getInstanceByName('prestablog')->generateToken($uid->id);
$link = call_user_func('PrestaBlog::prestablogUrl', [
'id' => $uid->id,
'seo' => $post->link_rewrite,
'titre' => $post->title,
'id_lang' => $uid->id_lang,
]);
break;
case UId::SIMPLEBLOG_POST:
$post = new \SimpleBlogPost($uid->id, $uid->id_lang, $uid->id_shop);
$cat = new \SimpleBlogCategory($post->id_simpleblog_category, $uid->id_lang, $uid->id_shop);
$link = call_user_func('SimpleBlogPost::getLink', $post->link_rewrite, $cat->link_rewrite);
break;
case UId::PSBLOG_POST:
$post = new \PsBlogBlog($uid->id, $uid->id_lang, $uid->id_shop);
$link = call_user_func('PsBlogHelper::getInstance')->getBlogLink([
'id_psblog_blog' => $post->id,
'link_rewrite' => $post->link_rewrite,
]);
break;
case UId::HIBLOG_POST:
$post = new \HiBlogPost($uid->id, $uid->id_lang, $uid->id_shop);
$link = \Module::getInstanceByName('hiblog')->returnBlogFrontUrl($post->id, $post->friendly_url, 'post');
break;
case UID::TVCMSBLOG_POST:
$link = call_user_func('TvcmsBlog::tvcmsBlogPostLink', [
'id' => $uid->id,
'rewrite' => call_user_func('TvcmsPostsClass::getTheRewrite', $uid->id),
]);
break;
default:
$method = "get{$uid->getModel()}Link";
$link = $ctx->link->$method($uid->id, null, $uid->id_lang, $id_shop, $relative);
break;
}
return explode('#', $link)[0] . (strrpos($link, '?') === false ? '?' : '&') . http_build_query($args);
}
function uidval($var, $fallback = -1)
{
if (null === $var) {
return get_the_ID();
}
if ($var instanceof UId) {
return $var;
}
if ($var instanceof WPPost) {
return $var->uid;
}
if (is_numeric($var)) {
return UId::parse($var);
}
if ($fallback !== -1) {
return $fallback;
}
throw new \RuntimeException('Can not convert to UId');
}
function get_edit_post_link($post_id)
{
$uid = uidval($post_id);
$ctx = \Context::getContext();
$id = $uid->id;
$model = $uid->getModel();
$admin = $uid->getAdminController();
switch ($uid->id_type) {
case UId::REVISION:
throw new \RuntimeException('TODO');
case UId::YBC_BLOG_POST:
$link = $ctx->link->getAdminLink($admin) . '&' . http_build_query([
'configure' => 'ybc_blog',
'tab_module' => 'front_office_features',
'module_name' => 'ybc_blog',
'control' => 'post',
'id_post' => $id,
]);
break;
case UId::PRESTABLOG_POST:
$link = $ctx->link->getAdminLink($admin) . "&configure=prestablog&editNews&idN=$id";
break;
case UId::CONTENT:
if (\Tools::getIsset('footerProduct')) {
$id = (int) \Tools::getValue('footerProduct');
$model = 'Product';
$admin = 'AdminProducts';
}
// Continue default case
default:
$def = &$model::${'definition'};
$args = [
$def['primary'] => $id,
"update{$def['table']}" => 1,
];
$link = $ctx->link->getAdminLink($admin, true, $args) . '&' . http_build_query($args);
break;
}
return $link;
}

View 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;