Skip to content

Commit cf085d2

Browse files
committed
Fix seoUrl for blog
1 parent 4cd58d8 commit cf085d2

File tree

2 files changed

+233
-2
lines changed

2 files changed

+233
-2
lines changed

model/blog/category.php

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,19 @@ public function getCategory($category_id)
3232
{
3333
$category = new CategoriesClass((int) $category_id, (int) $this->context->language->id, 1);
3434

35+
$url = $this->prestablogUrl(array(
36+
'c' => $category->id,
37+
'categorie' => $category->link_rewrite
38+
));
39+
3540
return array(
3641
'id' => $category->id,
3742
'name' => $category->title,
3843
'description' => html_entity_decode($category->description, ENT_QUOTES, 'UTF-8'),
3944
'parent_id' => $category->parent,
4045
'image' => $this->getImage($category->id),
4146
'imageLazy' => $this->getImageLazy($category->id),
42-
'keyword' => $category->link_rewrite
47+
'keyword' => $url
4348
);
4449
}
4550

@@ -135,4 +140,114 @@ public function getCategoryByPostId($post_id)
135140

136141
return $result;
137142
}
143+
144+
public function prestablogUrl($params)
145+
{
146+
$base_url_blog = 'blog';
147+
//$base_url_blog = 'articles';
148+
149+
$param = null;
150+
$ok_rewrite = '';
151+
$ok_rewrite_id = '';
152+
$ok_rewrite_do = '';
153+
$ok_rewrite_cat = '';
154+
$ok_rewrite_categorie = '';
155+
$ok_rewrite_page = '';
156+
$ok_rewrite_titre = '';
157+
$ok_rewrite_seo = '';
158+
$ok_rewrite_year = '';
159+
$ok_rewrite_month = '';
160+
161+
$ko_rewrite = '';
162+
$ko_rewrite_id = '';
163+
$ko_rewrite_do = '';
164+
$ko_rewrite_cat = '';
165+
$ko_rewrite_page = '';
166+
$ko_rewrite_year = '';
167+
$ko_rewrite_month = '';
168+
169+
if (isset($params['do']) && $params['do'] != '') {
170+
$ko_rewrite_do = 'do='.$params['do'];
171+
$ok_rewrite_do = $params['do'];
172+
$param += 1;
173+
}
174+
if (isset($params['id']) && $params['id'] != '') {
175+
$ko_rewrite_id = '&id='.$params['id'];
176+
$ok_rewrite_id = '-n'.$params['id'];
177+
$param += 1;
178+
}
179+
if (isset($params['c']) && $params['c'] != '') {
180+
$ko_rewrite_cat = '&c='.$params['c'];
181+
$ok_rewrite_cat = '-c'.$params['c'];
182+
$param += 1;
183+
}
184+
if (isset($params['start']) && isset($params['p']) && $params['start'] != '' && $params['p'] != '') {
185+
$ko_rewrite_page = '&start='.$params['start'].'&p='.$params['p'];
186+
$ok_rewrite_page = $params['start'].'p'.$params['p'];
187+
$param += 1;
188+
}
189+
if (isset($params['titre']) && $params['titre'] != '') {
190+
$ok_rewrite_titre = PrestaBlog::prestablogFilter(Tools::link_rewrite($params['titre']));
191+
$param += 1;
192+
}
193+
if (isset($params['categorie']) && $params['categorie'] != '') {
194+
$ok_rewrite_categorie = PrestaBlog::prestablogFilter(Tools::link_rewrite($params['categorie']));
195+
if (isset($params['start']) && isset($params['p']) && $params['start'] != '' && $params['p'] != '') {
196+
$ok_rewrite_categorie .= '-';
197+
} else {
198+
$ok_rewrite_categorie .= '';
199+
}
200+
$param += 1;
201+
}
202+
if (isset($params['seo']) && $params['seo'] != '') {
203+
$ok_rewrite_titre = PrestaBlog::prestablogFilter(Tools::link_rewrite($params['seo']));
204+
$param += 1;
205+
}
206+
if (isset($params['y']) && $params['y'] != '') {
207+
$ko_rewrite_year = '&y='.$params['y'];
208+
$ok_rewrite_year = 'y'.$params['y'];
209+
$param += 1;
210+
}
211+
if (isset($params['m']) && $params['m'] != '') {
212+
$ko_rewrite_month = '&m='.$params['m'];
213+
$ok_rewrite_month = '-m'.$params['m'];
214+
$param += 1;
215+
}
216+
if (isset($params['seo']) && $params['seo'] != '') {
217+
$ok_rewrite_seo = $params['seo'];
218+
$ok_rewrite_titre = '';
219+
$param += 1;
220+
}
221+
if (isset($params) && count($params) > 0 && !isset($params['rss'])) {
222+
$ok_rewrite = $base_url_blog.'/'.$ok_rewrite_do.$ok_rewrite_categorie.$ok_rewrite_page;
223+
$ok_rewrite .= $ok_rewrite_year.$ok_rewrite_month.$ok_rewrite_titre.$ok_rewrite_seo;
224+
$ok_rewrite .= $ok_rewrite_cat.$ok_rewrite_id;
225+
226+
$ko_rewrite = '?fc=module&module=prestablog&controller=blog&'.ltrim(
227+
$ko_rewrite_do.$ko_rewrite_id.$ko_rewrite_cat.$ko_rewrite_page.$ko_rewrite_year.$ko_rewrite_month,
228+
'&'
229+
);
230+
} elseif (isset($params['rss'])) {
231+
if ($params['rss'] == 'all') {
232+
$ok_rewrite = 'rss';
233+
$ko_rewrite = '?fc=module&module=prestablog&controller=rss';
234+
} else {
235+
$ok_rewrite = 'rss/'.$params['rss'];
236+
$ko_rewrite = '?fc=module&module=prestablog&controller=rss&rss='.$params['rss'];
237+
}
238+
} else {
239+
$ok_rewrite = $base_url_blog;
240+
$ko_rewrite = '?fc=module&module=prestablog&controller=blog';
241+
}
242+
243+
if (!isset($params['id_lang'])) {
244+
(int)$params['id_lang'] = null;
245+
}
246+
247+
if ((int)Configuration::get('PS_REWRITING_SETTINGS') && (int)Configuration::get('prestablog_rewrite_actif')) {
248+
return $ok_rewrite;
249+
} else {
250+
return $ko_rewrite;
251+
}
252+
}
138253
}

model/blog/post.php

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public function getPost($post_id)
3232
{
3333
$post = new NewsClass((int) $post_id, (int) $this->context->language->id, $this->context->shop->id);
3434

35+
$url = $this->prestablogUrl(array(
36+
'id' => $post->id,
37+
'seo' => $post->link_rewrite,
38+
'titre' => $post->title
39+
));
40+
3541
return array(
3642
'id' => $post->id,
3743
'title' => $post->title,
@@ -40,7 +46,7 @@ public function getPost($post_id)
4046
'shortDescription' => strip_tags(html_entity_decode($post->paragraph, ENT_QUOTES, 'UTF-8')),
4147
'image' => $this->getImage($post->id),
4248
'imageLazy' => $this->getImageLazy($post->id),
43-
'keyword' => $post->link_rewrite
49+
'keyword' => $url
4450
);
4551
}
4652

@@ -179,4 +185,114 @@ public function getPrevPost($post_id)
179185

180186
return $result;
181187
}
188+
189+
public function prestablogUrl($params)
190+
{
191+
$base_url_blog = 'blog';
192+
//$base_url_blog = 'articles';
193+
194+
$param = null;
195+
$ok_rewrite = '';
196+
$ok_rewrite_id = '';
197+
$ok_rewrite_do = '';
198+
$ok_rewrite_cat = '';
199+
$ok_rewrite_categorie = '';
200+
$ok_rewrite_page = '';
201+
$ok_rewrite_titre = '';
202+
$ok_rewrite_seo = '';
203+
$ok_rewrite_year = '';
204+
$ok_rewrite_month = '';
205+
206+
$ko_rewrite = '';
207+
$ko_rewrite_id = '';
208+
$ko_rewrite_do = '';
209+
$ko_rewrite_cat = '';
210+
$ko_rewrite_page = '';
211+
$ko_rewrite_year = '';
212+
$ko_rewrite_month = '';
213+
214+
if (isset($params['do']) && $params['do'] != '') {
215+
$ko_rewrite_do = 'do='.$params['do'];
216+
$ok_rewrite_do = $params['do'];
217+
$param += 1;
218+
}
219+
if (isset($params['id']) && $params['id'] != '') {
220+
$ko_rewrite_id = '&id='.$params['id'];
221+
$ok_rewrite_id = '-n'.$params['id'];
222+
$param += 1;
223+
}
224+
if (isset($params['c']) && $params['c'] != '') {
225+
$ko_rewrite_cat = '&c='.$params['c'];
226+
$ok_rewrite_cat = '-c'.$params['c'];
227+
$param += 1;
228+
}
229+
if (isset($params['start']) && isset($params['p']) && $params['start'] != '' && $params['p'] != '') {
230+
$ko_rewrite_page = '&start='.$params['start'].'&p='.$params['p'];
231+
$ok_rewrite_page = $params['start'].'p'.$params['p'];
232+
$param += 1;
233+
}
234+
if (isset($params['titre']) && $params['titre'] != '') {
235+
$ok_rewrite_titre = PrestaBlog::prestablogFilter(Tools::link_rewrite($params['titre']));
236+
$param += 1;
237+
}
238+
if (isset($params['categorie']) && $params['categorie'] != '') {
239+
$ok_rewrite_categorie = PrestaBlog::prestablogFilter(Tools::link_rewrite($params['categorie']));
240+
if (isset($params['start']) && isset($params['p']) && $params['start'] != '' && $params['p'] != '') {
241+
$ok_rewrite_categorie .= '-';
242+
} else {
243+
$ok_rewrite_categorie .= '';
244+
}
245+
$param += 1;
246+
}
247+
if (isset($params['seo']) && $params['seo'] != '') {
248+
$ok_rewrite_titre = PrestaBlog::prestablogFilter(Tools::link_rewrite($params['seo']));
249+
$param += 1;
250+
}
251+
if (isset($params['y']) && $params['y'] != '') {
252+
$ko_rewrite_year = '&y='.$params['y'];
253+
$ok_rewrite_year = 'y'.$params['y'];
254+
$param += 1;
255+
}
256+
if (isset($params['m']) && $params['m'] != '') {
257+
$ko_rewrite_month = '&m='.$params['m'];
258+
$ok_rewrite_month = '-m'.$params['m'];
259+
$param += 1;
260+
}
261+
if (isset($params['seo']) && $params['seo'] != '') {
262+
$ok_rewrite_seo = $params['seo'];
263+
$ok_rewrite_titre = '';
264+
$param += 1;
265+
}
266+
if (isset($params) && count($params) > 0 && !isset($params['rss'])) {
267+
$ok_rewrite = $base_url_blog.'/'.$ok_rewrite_do.$ok_rewrite_categorie.$ok_rewrite_page;
268+
$ok_rewrite .= $ok_rewrite_year.$ok_rewrite_month.$ok_rewrite_titre.$ok_rewrite_seo;
269+
$ok_rewrite .= $ok_rewrite_cat.$ok_rewrite_id;
270+
271+
$ko_rewrite = '?fc=module&module=prestablog&controller=blog&'.ltrim(
272+
$ko_rewrite_do.$ko_rewrite_id.$ko_rewrite_cat.$ko_rewrite_page.$ko_rewrite_year.$ko_rewrite_month,
273+
'&'
274+
);
275+
} elseif (isset($params['rss'])) {
276+
if ($params['rss'] == 'all') {
277+
$ok_rewrite = 'rss';
278+
$ko_rewrite = '?fc=module&module=prestablog&controller=rss';
279+
} else {
280+
$ok_rewrite = 'rss/'.$params['rss'];
281+
$ko_rewrite = '?fc=module&module=prestablog&controller=rss&rss='.$params['rss'];
282+
}
283+
} else {
284+
$ok_rewrite = $base_url_blog;
285+
$ko_rewrite = '?fc=module&module=prestablog&controller=blog';
286+
}
287+
288+
if (!isset($params['id_lang'])) {
289+
(int)$params['id_lang'] = null;
290+
}
291+
292+
if ((int)Configuration::get('PS_REWRITING_SETTINGS') && (int)Configuration::get('prestablog_rewrite_actif')) {
293+
return $ok_rewrite;
294+
} else {
295+
return $ko_rewrite;
296+
}
297+
}
182298
}

0 commit comments

Comments
 (0)