Рамиз Мирзаев

Add seo package

This diff could not be displayed because it is too large.
...@@ -845,7 +845,11 @@ class ModelToolSeoPackage extends Model { ...@@ -845,7 +845,11 @@ class ModelToolSeoPackage extends Model {
845 845
846 $this->session->data['kwCountArray'][$seo_kw]++; 846 $this->session->data['kwCountArray'][$seo_kw]++;
847 } 847 }
848 - 848 +
849 + if ($number == '') {
850 + $number = (int)$number;
851 + }
852 +
849 $search_kw = $seo_kw .'-'. ++$number; 853 $search_kw = $seo_kw .'-'. ++$number;
850 } 854 }
851 /* 855 /*
......
1 -<?php 1 +<?php
2 -// * @source See SOURCE.txt for source and other copyright. 2 +class ControllerStartupSeoUrl extends Controller {
3 -// * @license GNU General Public License version 3; see LICENSE.txt 3 + public function index() {
4 - 4 + // Add rewrite to url class
5 -class ControllerStartupSeoUrl extends Controller { 5 + if ($this->config->get('config_seo_url')) {
6 - 6 + $this->url->addRewrite($this);
7 - //seopro start 7 + }
8 - private $seo_pro; 8 +
9 - public function __construct($registry) { 9 + // Decode URL
10 - parent::__construct($registry); 10 + if (isset($this->request->get['_route_'])) {
11 - $this->seo_pro = new SeoPro($registry); 11 + $parts = explode('/', $this->request->get['_route_']);
12 - } 12 +
13 - //seopro end 13 + // remove any empty arrays from trailing
14 - 14 + if (utf8_strlen(end($parts)) == 0) {
15 - public function index() { 15 + array_pop($parts);
16 - 16 + }
17 - // Add rewrite to url class 17 +
18 - if ($this->config->get('config_seo_url')) { 18 + foreach ($parts as $part) {
19 - $this->url->addRewrite($this); 19 + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE keyword = '" . $this->db->escape($part) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'");
20 - } 20 +
21 - 21 + if ($query->num_rows) {
22 - 22 + $url = explode('=', $query->row['query']);
23 - // Decode URL 23 +
24 - if (isset($this->request->get['_route_'])) { 24 + if ($url[0] == 'product_id') {
25 - $parts = explode('/', $this->request->get['_route_']); 25 + $this->request->get['product_id'] = $url[1];
26 - 26 + }
27 - //seopro prepare route 27 +
28 - if($this->config->get('config_seo_pro')){ 28 + if ($url[0] == 'category_id') {
29 - $parts = $this->seo_pro->prepareRoute($parts); 29 + if (!isset($this->request->get['path'])) {
30 - } 30 + $this->request->get['path'] = $url[1];
31 - //seopro prepare route end 31 + } else {
32 - 32 + $this->request->get['path'] .= '_' . $url[1];
33 - // remove any empty arrays from trailing 33 + }
34 - if (utf8_strlen(end($parts)) == 0) { 34 + }
35 - array_pop($parts); 35 +
36 - } 36 + if ($url[0] == 'manufacturer_id') {
37 - 37 + $this->request->get['manufacturer_id'] = $url[1];
38 - foreach ($parts as $part) { 38 + }
39 - $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE keyword = '" . $this->db->escape($part) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'"); 39 +
40 - 40 + if ($url[0] == 'information_id') {
41 - if ($query->num_rows) { 41 + $this->request->get['information_id'] = $url[1];
42 - $url = explode('=', $query->row['query']); 42 + }
43 - 43 +
44 - if ($url[0] == 'product_id') { 44 + if ($query->row['query'] && $url[0] != 'information_id' && $url[0] != 'manufacturer_id' && $url[0] != 'category_id' && $url[0] != 'product_id') {
45 - $this->request->get['product_id'] = $url[1]; 45 + $this->request->get['route'] = $query->row['query'];
46 - } 46 + }
47 - 47 + } else {
48 - if ($url[0] == 'category_id') { 48 + $this->request->get['route'] = 'error/not_found';
49 - if (!isset($this->request->get['path'])) { 49 +
50 - $this->request->get['path'] = $url[1]; 50 + break;
51 - } else { 51 + }
52 - $this->request->get['path'] .= '_' . $url[1]; 52 + }
53 - } 53 +
54 - } 54 + if (!isset($this->request->get['route'])) {
55 - 55 + if (isset($this->request->get['product_id'])) {
56 - if ($url[0] == 'manufacturer_id') { 56 + $this->request->get['route'] = 'product/product';
57 - $this->request->get['manufacturer_id'] = $url[1]; 57 + } elseif (isset($this->request->get['path'])) {
58 - } 58 + $this->request->get['route'] = 'product/category';
59 - 59 + } elseif (isset($this->request->get['manufacturer_id'])) {
60 - if ($url[0] == 'information_id') { 60 + $this->request->get['route'] = 'product/manufacturer/info';
61 - $this->request->get['information_id'] = $url[1]; 61 + } elseif (isset($this->request->get['information_id'])) {
62 - } 62 + $this->request->get['route'] = 'information/information';
63 - 63 + }
64 - if ($query->row['query'] && $url[0] != 'information_id' && $url[0] != 'manufacturer_id' && $url[0] != 'category_id' && $url[0] != 'product_id') { 64 + }
65 - $this->request->get['route'] = $query->row['query']; 65 + }
66 - } 66 + }
67 - } else { 67 +
68 - if(!$this->config->get('config_seo_pro')){ 68 + public function rewrite($link) {
69 - $this->request->get['route'] = 'error/not_found'; 69 + $url_info = parse_url(str_replace('&amp;', '&', $link));
70 - } 70 +
71 - 71 + $url = '';
72 - break; 72 +
73 - } 73 + $data = array();
74 - } 74 +
75 - 75 + parse_str($url_info['query'], $data);
76 - if (!isset($this->request->get['route'])) { 76 +
77 - if (isset($this->request->get['product_id'])) { 77 + foreach ($data as $key => $value) {
78 - $this->request->get['route'] = 'product/product'; 78 + if (isset($data['route'])) {
79 - } elseif (isset($this->request->get['path'])) { 79 + if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) {
80 - $this->request->get['route'] = 'product/category'; 80 + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
81 - } elseif (isset($this->request->get['manufacturer_id'])) { 81 +
82 - $this->request->get['route'] = 'product/manufacturer/info'; 82 + if ($query->num_rows && $query->row['keyword']) {
83 - } elseif (isset($this->request->get['information_id'])) { 83 + $url .= '/' . $query->row['keyword'];
84 - $this->request->get['route'] = 'information/information'; 84 +
85 - } 85 + unset($data[$key]);
86 - } 86 + }
87 - } 87 + } elseif ($key == 'path') {
88 - 88 + $categories = explode('_', $value);
89 - //seopro validate 89 +
90 - if($this->config->get('config_seo_pro')){ 90 + foreach ($categories as $category) {
91 - $this->seo_pro->validate(); 91 + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = 'category_id=" . (int)$category . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
92 - } 92 +
93 - //seopro validate 93 + if ($query->num_rows && $query->row['keyword']) {
94 - 94 + $url .= '/' . $query->row['keyword'];
95 - } 95 + } else {
96 - 96 + $url = '';
97 - public function rewrite($link) { 97 +
98 - $url_info = parse_url(str_replace('&amp;', '&', $link)); 98 + break;
99 - 99 + }
100 - if($this->config->get('config_seo_pro')){ 100 + }
101 - $url = null; 101 +
102 - } else { 102 + unset($data[$key]);
103 - $url = ''; 103 + }
104 - } 104 + }
105 - 105 + }
106 - $data = array(); 106 +
107 - 107 + if ($url) {
108 - parse_str($url_info['query'], $data); 108 + unset($data['route']);
109 - 109 +
110 - //seo_pro baseRewrite 110 + $query = '';
111 - if($this->config->get('config_seo_pro')){ 111 +
112 - list($url, $data, $postfix) = $this->seo_pro->baseRewrite($data, (int)$this->config->get('config_language_id')); 112 + if ($data) {
113 - } 113 + foreach ($data as $key => $value) {
114 - 114 + $query .= '&' . rawurlencode((string)$key) . '=' . rawurlencode((is_array($value) ? http_build_query($value) : (string)$value));
115 - 115 + }
116 - 116 +
117 - 117 + if ($query) {
118 - //seo_pro baseRewrite 118 + $query = '?' . str_replace('&', '&amp;', trim($query, '&'));
119 - 119 + }
120 - foreach ($data as $key => $value) { 120 + }
121 - if (isset($data['route'])) { 121 +
122 - if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) { 122 + return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query;
123 - $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); 123 + } else {
124 - 124 + return $link;
125 - if ($query->num_rows && $query->row['keyword']) { 125 + }
126 - $url .= '/' . $query->row['keyword']; 126 + }
127 - 127 +}
128 - unset($data[$key]);
129 - }
130 - } elseif ($key == 'path') {
131 - $categories = explode('_', $value);
132 -
133 - foreach ($categories as $category) {
134 - $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = 'category_id=" . (int)$category . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
135 -
136 - if ($query->num_rows && $query->row['keyword']) {
137 - $url .= '/' . $query->row['keyword'];
138 - } else {
139 - $url = '';
140 -
141 - break;
142 - }
143 - }
144 -
145 - unset($data[$key]);
146 - }
147 - }
148 - }
149 -
150 - //seo_pro add blank url
151 - unset($data['route']);
152 -
153 - $query = '';
154 -
155 - if ($data) {
156 - foreach ($data as $key => $value) {
157 - $query .= '&' . rawurlencode((string)$key) . '=' . rawurlencode((is_array($value) ? http_build_query($value) : (string)$value));
158 - }
159 -
160 - if ($query) {
161 - $query = '?' . str_replace('&', '&amp;', trim($query, '&'));
162 - }
163 - }
164 -
165 - if($this->config->get('config_seo_pro')) {
166 - $condition = ($url !== null);
167 - } else {
168 - $condition = $url;
169 - }
170 -
171 - if ($condition) {
172 - if($this->config->get('config_seo_pro')){
173 - if($this->config->get('config_page_postfix') && $postfix) {
174 - $url .= $this->config->get('config_page_postfix');
175 - } elseif($this->config->get('config_seopro_addslash') || !empty( $query)) {
176 - $url .= '/';
177 - }
178 - }
179 -
180 - return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query;
181 - } else {
182 - return $link;
183 - }
184 - }
185 -}
......
1 +<?php
2 +// * @source See SOURCE.txt for source and other copyright.
3 +// * @license GNU General Public License version 3; see LICENSE.txt
4 +
5 +class ControllerStartupSeoUrl extends Controller {
6 +
7 + //seopro start
8 + private $seo_pro;
9 + public function __construct($registry) {
10 + parent::__construct($registry);
11 + $this->seo_pro = new SeoPro($registry);
12 + }
13 + //seopro end
14 +
15 + public function index() {
16 +
17 + // Add rewrite to url class
18 + if ($this->config->get('config_seo_url')) {
19 + $this->url->addRewrite($this);
20 + }
21 +
22 +
23 + // Decode URL
24 + if (isset($this->request->get['_route_'])) {
25 + $parts = explode('/', $this->request->get['_route_']);
26 +
27 + //seopro prepare route
28 + if($this->config->get('config_seo_pro')){
29 + $parts = $this->seo_pro->prepareRoute($parts);
30 + }
31 + //seopro prepare route end
32 +
33 + // remove any empty arrays from trailing
34 + if (utf8_strlen(end($parts)) == 0) {
35 + array_pop($parts);
36 + }
37 +
38 + foreach ($parts as $part) {
39 + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE keyword = '" . $this->db->escape($part) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'");
40 +
41 + if ($query->num_rows) {
42 + $url = explode('=', $query->row['query']);
43 +
44 + if ($url[0] == 'product_id') {
45 + $this->request->get['product_id'] = $url[1];
46 + }
47 +
48 + if ($url[0] == 'category_id') {
49 + if (!isset($this->request->get['path'])) {
50 + $this->request->get['path'] = $url[1];
51 + } else {
52 + $this->request->get['path'] .= '_' . $url[1];
53 + }
54 + }
55 +
56 + if ($url[0] == 'manufacturer_id') {
57 + $this->request->get['manufacturer_id'] = $url[1];
58 + }
59 +
60 + if ($url[0] == 'information_id') {
61 + $this->request->get['information_id'] = $url[1];
62 + }
63 +
64 + if ($query->row['query'] && $url[0] != 'information_id' && $url[0] != 'manufacturer_id' && $url[0] != 'category_id' && $url[0] != 'product_id') {
65 + $this->request->get['route'] = $query->row['query'];
66 + }
67 + } else {
68 + if(!$this->config->get('config_seo_pro')){
69 + $this->request->get['route'] = 'error/not_found';
70 + }
71 +
72 + break;
73 + }
74 + }
75 +
76 + if (!isset($this->request->get['route'])) {
77 + if (isset($this->request->get['product_id'])) {
78 + $this->request->get['route'] = 'product/product';
79 + } elseif (isset($this->request->get['path'])) {
80 + $this->request->get['route'] = 'product/category';
81 + } elseif (isset($this->request->get['manufacturer_id'])) {
82 + $this->request->get['route'] = 'product/manufacturer/info';
83 + } elseif (isset($this->request->get['information_id'])) {
84 + $this->request->get['route'] = 'information/information';
85 + }
86 + }
87 + }
88 +
89 + //seopro validate
90 + if($this->config->get('config_seo_pro')){
91 + $this->seo_pro->validate();
92 + }
93 + //seopro validate
94 +
95 + }
96 +
97 + public function rewrite($link) {
98 + $url_info = parse_url(str_replace('&amp;', '&', $link));
99 +
100 + if($this->config->get('config_seo_pro')){
101 + $url = null;
102 + } else {
103 + $url = '';
104 + }
105 +
106 + $data = array();
107 +
108 + parse_str($url_info['query'], $data);
109 +
110 + //seo_pro baseRewrite
111 + if($this->config->get('config_seo_pro')){
112 + list($url, $data, $postfix) = $this->seo_pro->baseRewrite($data, (int)$this->config->get('config_language_id'));
113 + }
114 +
115 +
116 +
117 +
118 + //seo_pro baseRewrite
119 +
120 + foreach ($data as $key => $value) {
121 + if (isset($data['route'])) {
122 + if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ($data['route'] == 'information/information' && $key == 'information_id')) {
123 + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
124 +
125 + if ($query->num_rows && $query->row['keyword']) {
126 + $url .= '/' . $query->row['keyword'];
127 +
128 + unset($data[$key]);
129 + }
130 + } elseif ($key == 'path') {
131 + $categories = explode('_', $value);
132 +
133 + foreach ($categories as $category) {
134 + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = 'category_id=" . (int)$category . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
135 +
136 + if ($query->num_rows && $query->row['keyword']) {
137 + $url .= '/' . $query->row['keyword'];
138 + } else {
139 + $url = '';
140 +
141 + break;
142 + }
143 + }
144 +
145 + unset($data[$key]);
146 + }
147 + }
148 + }
149 +
150 + //seo_pro add blank url
151 + unset($data['route']);
152 +
153 + $query = '';
154 +
155 + if ($data) {
156 + foreach ($data as $key => $value) {
157 + $query .= '&' . rawurlencode((string)$key) . '=' . rawurlencode((is_array($value) ? http_build_query($value) : (string)$value));
158 + }
159 +
160 + if ($query) {
161 + $query = '?' . str_replace('&', '&amp;', trim($query, '&'));
162 + }
163 + }
164 +
165 + if($this->config->get('config_seo_pro')) {
166 + $condition = ($url !== null);
167 + } else {
168 + $condition = $url;
169 + }
170 +
171 + if ($condition) {
172 + if($this->config->get('config_seo_pro')){
173 + if($this->config->get('config_page_postfix') && $postfix) {
174 + $url .= $this->config->get('config_page_postfix');
175 + } elseif($this->config->get('config_seopro_addslash') || !empty( $query)) {
176 + $url .= '/';
177 + }
178 + }
179 +
180 + return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query;
181 + } else {
182 + return $link;
183 + }
184 + }
185 +}