first commit

This commit is contained in:
2024-10-25 14:16:28 +02:00
commit 925276dbb2
33795 changed files with 4780077 additions and 0 deletions

View File

@@ -0,0 +1,255 @@
<?php
/**
* 2019 ModuleFactory.co
*
* @author ModuleFactory.co <info@modulefactory.co>
* @copyright 2019 ModuleFactory.co
* @license ModuleFactory.co Commercial License
*/
class Dispatcher extends DispatcherCore
{
public function getRoutes()
{
return $this->routes;
}
public function getRequestUri()
{
return $this->request_uri;
}
protected function loadRoutes($id_shop = null)
{
parent::loadRoutes($id_shop);
if (Module::isEnabled('fsadvancedurl')) {
$fsau = Module::getInstanceByName('fsadvancedurl');
$this->routes = $fsau->dispatcherLoadRoutes($this->routes, $this);
}
}
protected function setRequestUri()
{
parent::setRequestUri();
$remove_enabled = Configuration::get('FSAU_REMOVE_DEFAULT_LANG');
$current_iso_lang = Tools::getValue('isolang');
if ($this->use_routes && Language::isMultiLanguageActivated() && !$current_iso_lang && $remove_enabled) {
$_GET['isolang'] = Language::getIsoById(Configuration::get('PS_LANG_DEFAULT'));
}
}
public function getController($id_shop = null)
{
if (defined('_PS_ADMIN_DIR_')) {
$_GET['controllerUri'] = Tools::getvalue('controller');
}
if ($this->controller) {
$_GET['controller'] = $this->controller;
return $this->controller;
}
if (isset(Context::getContext()->shop) && $id_shop === null) {
$id_shop = (int)Context::getContext()->shop->id;
}
$id_lang = Context::getContext()->language->id;
$controller = Tools::getValue('controller');
if (isset($controller) && is_string($controller) &&
preg_match('/^([0-9a-z_-]+)\?(.*)=(.*)$/Ui', $controller, $m)) {
$controller = $m[1];
if (isset($_GET['controller'])) {
$_GET[$m[2]] = $m[3];
} elseif (isset($_POST['controller'])) {
$_POST[$m[2]] = $m[3];
}
}
if (!Validate::isControllerName($controller)) {
$controller = false;
}
if ($this->use_routes && !$controller && !defined('_PS_ADMIN_DIR_')) {
if (!$this->request_uri) {
return Tools::strtolower($this->controller_not_found);
}
$controller = $this->controller_not_found;
$test_request_uri = preg_replace('/(=http:\/\/)/', '=', $this->request_uri);
if (!preg_match('/\.(gif|jpe?g|png|css|js|ico)$/i', parse_url($test_request_uri, PHP_URL_PATH))) {
if ($this->empty_route) {
$this->addRoute(
$this->empty_route['routeID'],
$this->empty_route['rule'],
$this->empty_route['controller'],
$id_lang,
array(),
array(),
$id_shop
);
}
list($uri) = explode('?', $this->request_uri);
if (Tools::file_exists_cache(_PS_ROOT_DIR_.$uri)) {
return $controller;
}
if (isset($this->routes[$id_shop][$id_lang])) {
$maybe_matched = array();
$last_checked_route = array();
foreach ($this->routes[$id_shop][$id_lang] as $route_id => $route) {
if (preg_match($route['regexp'], $uri, $m)) {
if (Module::isEnabled('fsadvancedurl')) {
$fsau = Module::getInstanceByName('fsadvancedurl');
if ($fsau->isHandleRoute($route_id)) {
//Little help for the "{categories:/}{rewrite}" rule when the url ends with a "/".
$m = $fsau->fixRegexResult($m);
//Start debugging
$debug_data = array('m' => $m, 'route' => $route);
//Check rewrite against the content type
$pre_dispatcher = $fsau->getRoutePreDispatcher($route_id);
if ($pre_dispatcher &&
Tools::isCallable(array(
$pre_dispatcher['module'],
$pre_dispatcher['function']
))) {
$info_module_pre_dispatcher = call_user_func(array(
$pre_dispatcher['module'],
$pre_dispatcher['function']
), $uri, $route_id, $route, $m, $id_lang, $id_shop);
$info = $fsau->getPreDispatcherDefaultResponse();
if (is_array($info_module_pre_dispatcher)) {
$info = array_merge($info, $info_module_pre_dispatcher);
}
$debug_data['pre_dispatch_info'] = $info;
$debug_data['pre_dispatcher'] = get_class($pre_dispatcher['module']).'::';
$debug_data['pre_dispatcher'] .= $pre_dispatcher['function'];
} else {
$info = $fsau->preDispatch($uri, $route_id, $route, $m, $id_lang, $id_shop);
$debug_data['pre_dispatch_info'] = $info;
}
//Save debug info for checked route
$fsau->debug_data['checked_routes'][$route_id] = $debug_data;
//Save the last checked route as a fallback
//Later check use it or not
$last_checked_route = array(
'route_name' => $route_id,
'm' => $m,
'route' => $route,
'use_when_maybe' => $info['use_when_maybe']
);
//If 100% matched the controller
if ($info['is_matched_controller']) {
if ($info['id'] && $info['property']) {
$_GET[$info['property']] = $info['id'];
}
} else {
//If the route maybe matched add to a second investigation
if ($info['maybe_matched_controller']) {
$maybe_matched[$route_id] = array(
'm' => $m,
'route' => $route,
'use_when_maybe' => $info['use_when_maybe']
);
}
//Skip the rest of the code because have to check the other matched routes
continue;
}
}
}
//Now we have a fix match so clear the maybe list and the last as well no need for fallback
$maybe_matched = array();
$last_checked_route = array();
foreach ($m as $k => $v) {
if (!is_numeric($k)) {
$_GET[$k] = $v;
}
}
$controller = $route['controller'] ? $route['controller'] : $_GET['controller'];
if (!empty($route['params'])) {
foreach ($route['params'] as $k => $v) {
$_GET[$k] = $v;
}
}
if (preg_match('#module-([a-z0-9_-]+)-([a-z0-9_]+)$#i', $controller, $m)) {
$_GET['module'] = $m[1];
$_GET['fc'] = 'module';
$controller = $m[2];
}
if (isset($_GET['fc']) && $_GET['fc'] == 'module') {
$this->front_controller = self::FC_MODULE;
}
break;
}
}
//Add the last checked route to the final check
if (!$maybe_matched && $last_checked_route) {
$maybe_matched[$last_checked_route['route_name']] = array(
'm' => $last_checked_route['m'],
'route' => $last_checked_route['route'],
'use_when_maybe' => $last_checked_route['use_when_maybe']
);
}
if ($maybe_matched) {
foreach ($maybe_matched as $route_data) {
$m = $route_data['m'];
$route = $route_data['route'];
if ($route_data['use_when_maybe']) {
foreach ($m as $k => $v) {
if (!is_numeric($k)) {
$_GET[$k] = $v;
}
}
$controller = $route['controller'] ? $route['controller'] : $_GET['controller'];
if (!empty($route['params'])) {
foreach ($route['params'] as $k => $v) {
$_GET[$k] = $v;
}
}
if (preg_match('#module-([a-z0-9_-]+)-([a-z0-9_]+)$#i', $controller, $m)) {
$_GET['module'] = $m[1];
$_GET['fc'] = 'module';
$controller = $m[2];
}
if (isset($_GET['fc']) && $_GET['fc'] == 'module') {
$this->front_controller = self::FC_MODULE;
}
break;
}
}
}
}
}
if ($controller == 'index' || preg_match('/^\/index.php(?:\?.*)?$/', $this->request_uri)) {
$controller = $this->useDefaultController();
}
}
$this->controller = str_replace('-', '', $controller);
$_GET['controller'] = $this->controller;
return $this->controller;
}
}

View File

@@ -0,0 +1,244 @@
<?php
/**
* 2019 ModuleFactory.co
*
* @author ModuleFactory.co <info@modulefactory.co>
* @copyright 2019 ModuleFactory.co
* @license ModuleFactory.co Commercial License
*/
class Link extends LinkCore
{
protected function getLangLink($id_lang = null, Context $context = null, $id_shop = null)
{
if (Configuration::get('FSAU_REMOVE_DEFAULT_LANG', null, null, $id_shop) &&
Language::isMultiLanguageActivated()) {
if (!$id_lang) {
if (is_null($context)) {
$context = Context::getContext();
}
$id_lang = $context->language->id;
}
if ($id_lang == Configuration::get('PS_LANG_DEFAULT', null, null, $id_shop)) {
return '';
}
}
return parent::getLangLink($id_lang, $context, $id_shop);
}
public function getCategoryLink(
$category,
$alias = null,
$id_lang = null,
$selected_filters = null,
$id_shop = null,
$relative_protocol = false
) {
if (!$id_lang) {
$id_lang = Context::getContext()->language->id;
}
$url = $this->getBaseLink($id_shop, null, $relative_protocol).$this->getLangLink($id_lang, null, $id_shop);
if (!is_object($category)) {
if (is_array($category) && isset($category['id_category'])) {
$category = new Category($category['id_category'], $id_lang);
} elseif ((int)$category) {
$category = new Category((int)$category, $id_lang);
} else {
return '';
}
}
$params = array();
$params['id'] = $category->id;
$params['rewrite'] = (!$alias) ? $category->getFieldByLang('link_rewrite') : $alias;
$params['meta_keywords'] = Tools::str2url($category->getFieldByLang('meta_keywords'));
$params['meta_title'] = Tools::str2url($category->getFieldByLang('meta_title'));
$dispatcher = Dispatcher::getInstance();
if ($dispatcher->hasKeyword('category_rule', $id_lang, 'categories', $id_shop)) {
$cats = array();
foreach ($category->getParentsCategories($id_lang) as $cat) {
if (!in_array($cat['id_category'], Link::$category_disable_rewrite)) {
$cats[] = $cat['link_rewrite'];
}
}
$cats = array_reverse($cats);
array_pop($cats);
$params['categories'] = implode('/', $cats);
}
$selected_filters = is_null($selected_filters) ? '' : $selected_filters;
if (empty($selected_filters)) {
$rule = 'category_rule';
} else {
$rule = 'layered_rule';
$params['selected_filters'] = $selected_filters;
}
return $url.Dispatcher::getInstance()->createUrl($rule, $id_lang, $params, $this->allow, '', $id_shop);
}
public function getProductLink(
$product,
$alias = null,
$category = null,
$ean13 = null,
$idLang = null,
$idShop = null,
$ipa = 0,
$force_routes = false,
$relativeProtocol = false,
$addAnchor = false,
$extraParams = array()
) {
$remove_anchor = false;
if (Module::isEnabled('fsadvancedurl')) {
$fsau = Module::getInstanceByName('fsadvancedurl');
$remove_anchor = $fsau->isRemoveAnchor($product, $ipa);
}
if ($remove_anchor) {
$ipa = 0;
}
return parent::getProductLink(
$product,
$alias,
$category,
$ean13,
$idLang,
$idShop,
$ipa,
$force_routes,
$relativeProtocol,
$addAnchor,
$extraParams
);
}
public function getCMSCategoryLink(
$cms_category,
$alias = null,
$id_lang = null,
$id_shop = null,
$relative_protocol = false
) {
if (!$id_lang) {
$id_lang = Context::getContext()->language->id;
}
$url = $this->getBaseLink($id_shop, null, $relative_protocol).$this->getLangLink($id_lang, null, $id_shop);
$dispatcher = Dispatcher::getInstance();
if (!is_object($cms_category)) {
$cms_category = new CMSCategory((int)$cms_category, $id_lang);
}
// Set available keywords
$params = array();
$params['id'] = $cms_category->id;
$params['rewrite'] = $cms_category->link_rewrite;
if (is_array($params['rewrite']) && isset($params['rewrite'][(int)$id_lang])) {
$params['rewrite'] = $params['rewrite'][(int)$id_lang];
}
if ($alias) {
$params['rewrite'] = $alias;
}
$params['meta_keywords'] = $cms_category->meta_keywords;
if (is_array($params['meta_keywords']) && isset($params['meta_keywords'][(int)$id_lang])) {
$params['meta_keywords'] = Tools::str2url($params['meta_keywords'][(int)$id_lang]);
}
$params['meta_title'] = $cms_category->meta_title;
if (is_array($params['meta_title']) && isset($params['meta_title'][(int)$id_lang])) {
$params['meta_title'] = Tools::str2url($params['meta_title'][(int)$id_lang]);
}
if ($dispatcher->hasKeyword('cms_category_rule', $id_lang, 'categories', $id_shop)) {
$cats = array();
if (Module::isEnabled('fsadvancedurl')) {
$fsau = Module::getInstanceByName('fsadvancedurl');
$categories = $fsau->getCMSCategoryParentCategories($cms_category->id, $id_lang);
if ($categories) {
foreach ($categories as $cat) {
$cats[] = $cat['link_rewrite'];
}
$cats = array_reverse($cats);
array_pop($cats);
}
}
$params['categories'] = implode('/', $cats);
}
return $url.$dispatcher->createUrl('cms_category_rule', $id_lang, $params, $this->allow, '', $id_shop);
}
public function getCMSLink(
$cms,
$alias = null,
$ssl = null,
$id_lang = null,
$id_shop = null,
$relative_protocol = false
) {
if (!$id_lang) {
$id_lang = Context::getContext()->language->id;
}
$url = $this->getBaseLink($id_shop, $ssl, $relative_protocol).$this->getLangLink($id_lang, null, $id_shop);
$dispatcher = Dispatcher::getInstance();
if (!is_object($cms)) {
$cms = new CMS((int)$cms, $id_lang);
}
// Set available keywords
$params = array();
$params['id'] = $cms->id;
$params['rewrite'] = $cms->link_rewrite;
if (is_array($params['rewrite']) && isset($params['rewrite'][(int)$id_lang])) {
$params['rewrite'] = $params['rewrite'][(int)$id_lang];
}
if ($alias) {
$params['rewrite'] = $alias;
}
$params['meta_keywords'] = $cms->meta_keywords;
if (is_array($params['meta_keywords']) && isset($params['meta_keywords'][(int)$id_lang])) {
$params['meta_keywords'] = Tools::str2url($params['meta_keywords'][(int)$id_lang]);
}
$params['meta_title'] = $cms->meta_title;
if (is_array($params['meta_title']) && isset($params['meta_title'][(int)$id_lang])) {
$params['meta_title'] = Tools::str2url($params['meta_title'][(int)$id_lang]);
}
if ($dispatcher->hasKeyword('cms_rule', $id_lang, 'categories', $id_shop)) {
$cats = array();
$cms_category = new CMSCategory($cms->id_cms_category, $id_lang);
if (Validate::isLoadedObject($cms_category)) {
if (Module::isEnabled('fsadvancedurl')) {
$fsau = Module::getInstanceByName('fsadvancedurl');
$categories = $fsau->getCMSCategoryParentCategories($cms_category->id, $id_lang);
if ($categories) {
foreach ($categories as $cat) {
$cats[] = $cat['link_rewrite'];
}
$cats = array_reverse($cats);
}
}
}
$params['categories'] = implode('/', $cats);
}
return $url.$dispatcher->createUrl('cms_rule', $id_lang, $params, $this->allow, '', $id_shop);
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* 2019 ModuleFactory.co
*
* @author ModuleFactory.co <info@modulefactory.co>
* @copyright 2019 ModuleFactory.co
* @license ModuleFactory.co Commercial License
*/
class FrontController extends FrontControllerCore
{
protected function canonicalRedirection($canonical_url = '')
{
$fsau_params = array();
if (Module::isEnabled('fsadvancedurl')) {
$fsau = Module::getInstanceByName('fsadvancedurl');
$info = $fsau->overrideCanonicalUrl($canonical_url);
$canonical_url = $info['canonical_url'];
if (isset($info['params']) && is_array($info['params']) && $info['params']) {
$fsau_params = $info['params'];
}
}
parent::canonicalRedirection($canonical_url);
if ($fsau_params) {
$_GET = array_merge($_GET, $fsau_params);
}
}
protected function updateQueryString(array $extraParams = null)
{
$uriWithoutParams = explode('?', $_SERVER['REQUEST_URI']);
if (isset($uriWithoutParams[0])) {
$uriWithoutParams = $uriWithoutParams[0];
}
$url = Tools::getCurrentUrlProtocolPrefix().$_SERVER['HTTP_HOST'].$uriWithoutParams;
if (Module::isEnabled('fsadvancedurl')) {
$fsau = Module::getInstanceByName('fsadvancedurl');
$url = $fsau->overrideUpdateQueryStringBaseUrl($url, $extraParams);
}
$params = array();
parse_str($_SERVER['QUERY_STRING'], $params);
if (null !== $extraParams) {
foreach ($extraParams as $key => $value) {
if (null === $value) {
unset($params[$key]);
} else {
$params[$key] = $value;
}
}
}
ksort($params);
if (null !== $extraParams) {
foreach ($params as $key => $param) {
if (null === $param || '' === $param) {
unset($params[$key]);
}
}
} else {
$params = array();
}
$queryString = str_replace('%2F', '/', http_build_query($params));
return $url.($queryString ? "?$queryString" : '');
}
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* 2019 ModuleFactory.co
*
* @author ModuleFactory.co <info@modulefactory.co>
* @copyright 2019 ModuleFactory.co
* @license ModuleFactory.co Commercial License
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,16 @@
<?php
/**
* 2019 ModuleFactory.co
*
* @author ModuleFactory.co <info@modulefactory.co>
* @copyright 2019 ModuleFactory.co
* @license ModuleFactory.co Commercial License
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;