Система регионов
This commit is contained in:
@@ -19,7 +19,7 @@ class ControllerCommonCity extends Controller {
|
||||
);
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('common/city/save');
|
||||
$data['action'] = $this->url->link('common/city/save', '', true);
|
||||
|
||||
$this->response->setOutput($this->load->view('common/city_list', $data));
|
||||
}
|
||||
@@ -28,12 +28,23 @@ class ControllerCommonCity extends Controller {
|
||||
$json = array();
|
||||
|
||||
if (isset($this->request->post['city_id'])) {
|
||||
$this->session->data['city_id'] = (int)$this->request->post['city_id'];
|
||||
$json['success'] = true;
|
||||
|
||||
$this->load->model('localisation/zone');
|
||||
$zone = $this->model_localisation_zone->getZone($this->session->data['city_id']);
|
||||
$json['name'] = $zone ? $zone['name'] : '';
|
||||
|
||||
$zone = $this->model_localisation_zone->getZone((int)$this->request->post['city_id']);
|
||||
|
||||
if (!$zone || (int)$zone['country_id'] !== (int)$this->config->get('config_country_id')) {
|
||||
$json['success'] = false;
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->session->data['city_id'] = (int)$zone['zone_id'];
|
||||
$json['success'] = true;
|
||||
$json['name'] = $zone['name'];
|
||||
$json['redirect'] = $this->model_localisation_zone->getZoneUrl($zone['zone_id'], isset($this->request->post['redirect']) ? $this->request->post['redirect'] : $this->url->link('common/home'));
|
||||
} else {
|
||||
$json['success'] = false;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ foreach(['name','email','telephone','address','open', 'comment'] as $item){
|
||||
}
|
||||
}
|
||||
|
||||
$data['city_list_url'] = $this->url->link('common/city');
|
||||
$data['city_list_url'] = $this->url->link('common/city', '', true);
|
||||
|
||||
return $this->load->view('common/header', $data);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ class ControllerProductManufacturer extends Controller {
|
||||
}
|
||||
|
||||
$data['continue'] = $this->url->link('common/home');
|
||||
$data['manufacturer'] = $this->url->link('product/manufacturer');
|
||||
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['column_right'] = $this->load->controller('common/column_right');
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ControllerStartupSeoUrl extends Controller {
|
||||
private $region_slug = '';
|
||||
|
||||
//seopro start
|
||||
private $seo_pro;
|
||||
@@ -13,25 +14,20 @@ class ControllerStartupSeoUrl extends Controller {
|
||||
//seopro end
|
||||
|
||||
public function index() {
|
||||
|
||||
// Add rewrite to url class
|
||||
if ($this->config->get('config_seo_url')) {
|
||||
$this->url->addRewrite($this);
|
||||
}
|
||||
|
||||
|
||||
// Decode URL
|
||||
if (isset($this->request->get['_route_'])) {
|
||||
$parts = explode('/', $this->request->get['_route_']);
|
||||
|
||||
$this->prepareRegion($parts);
|
||||
|
||||
//seopro prepare route
|
||||
if($this->config->get('config_seo_pro')){
|
||||
$parts = $this->seo_pro->prepareRoute($parts);
|
||||
}
|
||||
//seopro prepare route end
|
||||
//seopro prepare route
|
||||
if($this->config->get('config_seo_pro')){
|
||||
$parts = $this->seo_pro->prepareRoute($parts);
|
||||
}
|
||||
//seopro prepare route end
|
||||
|
||||
// remove any empty arrays from trailing
|
||||
if (utf8_strlen(end($parts)) == 0) {
|
||||
if ($parts && utf8_strlen(end($parts)) == 0) {
|
||||
array_pop($parts);
|
||||
}
|
||||
|
||||
@@ -85,6 +81,15 @@ class ControllerStartupSeoUrl extends Controller {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($this->request->get['_route_']) && parse_url($this->request->server['REQUEST_URI'], PHP_URL_PATH) === '/') {
|
||||
$this->setRegion((int)$this->config->get('config_zone_id'));
|
||||
} elseif ($this->region_slug === '') {
|
||||
$this->loadRegionFromSession();
|
||||
}
|
||||
|
||||
// Add rewrite to url class
|
||||
$this->url->addRewrite($this);
|
||||
|
||||
//seopro validate
|
||||
if($this->config->get('config_seo_pro')){
|
||||
@@ -95,6 +100,10 @@ class ControllerStartupSeoUrl extends Controller {
|
||||
}
|
||||
|
||||
public function rewrite($link) {
|
||||
if (!$this->config->get('config_seo_url')) {
|
||||
return $this->addRegionPrefix($link);
|
||||
}
|
||||
|
||||
$url_info = parse_url(str_replace('&', '&', $link));
|
||||
|
||||
if($this->config->get('config_seo_pro')){
|
||||
@@ -177,9 +186,96 @@ class ControllerStartupSeoUrl extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query;
|
||||
return $this->addRegionPrefix($url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query);
|
||||
} else {
|
||||
return $link;
|
||||
return $this->addRegionPrefix($link);
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareRegion(&$parts) {
|
||||
$parts = array_values(array_filter($parts, 'strlen'));
|
||||
$zone = array();
|
||||
|
||||
if (isset($parts[0])) {
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
$zone = $this->model_localisation_zone->getZoneBySlug($parts[0], $this->config->get('config_country_id'));
|
||||
}
|
||||
|
||||
if ($zone) {
|
||||
array_shift($parts);
|
||||
$this->setRegion((int)$zone['zone_id'], $zone['slug']);
|
||||
} else {
|
||||
$this->setRegion((int)$this->config->get('config_zone_id'));
|
||||
}
|
||||
|
||||
if ($parts) {
|
||||
$this->request->get['_route_'] = implode('/', $parts);
|
||||
} else {
|
||||
unset($this->request->get['_route_']);
|
||||
}
|
||||
}
|
||||
|
||||
private function loadRegionFromSession() {
|
||||
if (!isset($this->session->data['city_id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
$zone = $this->model_localisation_zone->getZone($this->session->data['city_id']);
|
||||
|
||||
if ($zone && (int)$zone['country_id'] === (int)$this->config->get('config_country_id')) {
|
||||
$this->setRegion((int)$zone['zone_id'], $zone['slug']);
|
||||
}
|
||||
}
|
||||
|
||||
private function setRegion($zone_id, $slug = '') {
|
||||
$this->session->data['city_id'] = (int)$zone_id;
|
||||
$this->region_slug = ((int)$zone_id === (int)$this->config->get('config_zone_id')) ? '' : $slug;
|
||||
}
|
||||
|
||||
private function addRegionPrefix($link) {
|
||||
if ($this->region_slug === '') {
|
||||
return $link;
|
||||
}
|
||||
|
||||
$url_info = parse_url(str_replace('&', '&', $link));
|
||||
|
||||
if (!$url_info || !isset($url_info['scheme']) || !isset($url_info['host'])) {
|
||||
return $link;
|
||||
}
|
||||
|
||||
$path = isset($url_info['path']) ? preg_replace('#/index\.php$#', '', $url_info['path']) : '';
|
||||
$base_path = parse_url($this->config->get('config_url'), PHP_URL_PATH);
|
||||
$base_path = '/' . trim((string)$base_path, '/');
|
||||
|
||||
if ($base_path === '/') {
|
||||
$base_path = '';
|
||||
}
|
||||
|
||||
if ($base_path !== '' && ($path === $base_path || strpos($path, $base_path . '/') === 0)) {
|
||||
$relative_path = substr($path, strlen($base_path));
|
||||
} else {
|
||||
$relative_path = $path;
|
||||
}
|
||||
|
||||
$parts = array_values(array_filter(explode('/', trim($relative_path, '/')), 'strlen'));
|
||||
|
||||
if (!isset($parts[0]) || $parts[0] !== $this->region_slug) {
|
||||
array_unshift($parts, $this->region_slug);
|
||||
}
|
||||
|
||||
$link = $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . $base_path . '/' . implode('/', $parts);
|
||||
|
||||
if (isset($url_info['query'])) {
|
||||
$link .= '?' . str_replace('&', '&', $url_info['query']);
|
||||
}
|
||||
|
||||
if (isset($url_info['fragment'])) {
|
||||
$link .= '#' . $url_info['fragment'];
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user