Skip to content

Commit 75774de

Browse files
committed
Added new API. Fix bug.
1 parent 112e42d commit 75774de

File tree

18 files changed

+248
-154
lines changed

18 files changed

+248
-154
lines changed

mapping.json

100755100644
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"accountEditAddress": "common/account/editAddress",
1212
"accountRemoveAddress": "common/account/removeAddress",
1313

14+
"home": "common/home/get",
15+
1416
"uploadFile": "common/file/upload",
1517

1618
"countriesList": "common/country/getList",

model/blog/category.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ public function getCategory($category_id)
4646
'parent_id' => $category->parent,
4747
'image' => $this->getImage($category->id),
4848
'imageLazy' => $this->getImageLazy($category->id),
49-
'keyword' => $url
49+
'keyword' => $url,
50+
'meta' => array(
51+
'title' => $category->meta_title,
52+
'description' => $category->meta_description,
53+
'keyword' => $category->meta_keywords,
54+
),
5055
);
5156
}
5257

@@ -88,7 +93,7 @@ public function getCategories($data = array())
8893
$sql->where('cl.`id_lang` = ' . (int) $language_id);
8994

9095
if (isset($data['filter_parent_id'])) {
91-
$sql->where('c.`parent` = ' . $data['filter_parent_id']);
96+
$sql->where('c.`parent` = ' . (int)$data['filter_parent_id']);
9297
}
9398

9499
$sql->orderBy($sort . ' ' . $order);
@@ -119,7 +124,7 @@ public function getTotalCategories($data = array())
119124
$sql->where('cl.`id_lang` = ' . (int) $language_id);
120125

121126
if ($parent_id) {
122-
$sql->where('c.`id_parent` = ' . $parent_id);
127+
$sql->where('c.`id_parent` = ' . (int) $parent_id);
123128
}
124129

125130
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);

model/blog/post.php

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
* @author VueFront
2222
* @copyright Copyright (c) permanent, VueFront
2323
* @license MIT
24+
*
2425
* @version 0.1.0
2526
*/
26-
2727
include_once _PS_MODULE_DIR_ . 'prestablog/class/news.class.php';
2828

2929
class ModelBlogPost extends Model
@@ -37,7 +37,7 @@ public function getPost($post_id)
3737
$url = $this->model_blog_url->link(array(
3838
'id' => $post->id,
3939
'seo' => $post->link_rewrite,
40-
'titre' => $post->title
40+
'titre' => $post->title,
4141
));
4242

4343
return array(
@@ -48,16 +48,22 @@ public function getPost($post_id)
4848
'shortDescription' => strip_tags(html_entity_decode($post->paragraph, ENT_QUOTES, 'UTF-8')),
4949
'image' => $this->getImage($post->id),
5050
'imageLazy' => $this->getImageLazy($post->id),
51-
'keyword' => $url
51+
'keyword' => $url,
52+
'meta' => array(
53+
'title' => $post->meta_title,
54+
'description' => $post->meta_description,
55+
'keyword' => $post->meta_keywords,
56+
),
5257
);
5358
}
5459

5560
public function getImage($post_id)
5661
{
57-
if (file_exists(_PS_ROOT_DIR_. '/modules/prestablog/views/img/' . Configuration::get('prestablog_theme') .
62+
if (file_exists(_PS_ROOT_DIR_ . '/modules/prestablog/views/img/' . Configuration::get('prestablog_theme') .
5863
'/up-img/' . $post_id . '.jpg')) {
5964
$uri = __PS_BASE_URI__ . 'modules/prestablog/views/img/' . Configuration::get('prestablog_theme') .
6065
'/up-img/' . $post_id . '.jpg';
66+
6167
return $this->context->link->protocol_content . Tools::getMediaServer($uri) . $uri;
6268
} else {
6369
return '';
@@ -66,10 +72,11 @@ public function getImage($post_id)
6672

6773
public function getImageLazy($post_id)
6874
{
69-
if (file_exists(_PS_ROOT_DIR_. '/modules/prestablog/views/img/' . Configuration::get('prestablog_theme') .
75+
if (file_exists(_PS_ROOT_DIR_ . '/modules/prestablog/views/img/' . Configuration::get('prestablog_theme') .
7076
'/up-img/thumb_' . $post_id . '.jpg')) {
7177
$uri = __PS_BASE_URI__ . 'modules/prestablog/views/img/' . Configuration::get('prestablog_theme') .
7278
'/up-img/thumb_' . $post_id . '.jpg';
79+
7380
return $this->context->link->protocol_content . Tools::getMediaServer($uri) . $uri;
7481
} else {
7582
return '';
@@ -80,15 +87,15 @@ public function getPosts($data = array())
8087
{
8188
$sort = 'pn.`id_prestablog_news`';
8289
if ($data['sort'] == 'sort_order') {
83-
$sort = "pn.`id_prestablog_news`";
90+
$sort = 'pn.`id_prestablog_news`';
8491
}
8592

8693
if ($data['sort'] == 'date_added') {
87-
$sort = "pn.`date`";
94+
$sort = 'pn.`date`';
8895
}
8996

9097
if ($data['sort'] == 'name') {
91-
$sort = "pnl.`title`";
98+
$sort = 'pnl.`title`';
9299
}
93100

94101
$sql = new DbQuery();
@@ -107,13 +114,13 @@ public function getPosts($data = array())
107114

108115
if (!empty($data['filter_post_ids'])) {
109116
$sql->where('p.`id_prestablog_news` IN ' . "('" .
110-
implode("','", explode(",", preg_replace('/\s+/', ' ', $data['filter_post_ids']))) . "')");
117+
pSQL(implode("','", explode(',', preg_replace('/\s+/', ' ', $data['filter_post_ids'])))) . "')");
111118
}
112119

113120
if (!empty($data['filter_description']) && !empty($data['filter_name'])) {
114-
$sql->where("pnl.`title` = '%" . $data['filter_name'] .
115-
"%' OR pnl.content = '%" . $data['filter_description'] .
116-
"%' OR pnl.paragraph = '%" . $data['filter_description'] . "%'");
121+
$sql->where("pnl.`title` = '%" . pSQL($data['filter_name']) .
122+
"%' OR pnl.content = '%" . pSQL($data['filter_description']) .
123+
"%' OR pnl.paragraph = '%" . pSQL($data['filter_description']) . "%'");
117124
}
118125

119126
$sql->orderBy($sort . ' ' . $data['order']);
@@ -144,17 +151,18 @@ public function getTotalPosts($data = array())
144151

145152
if (!empty($data['filter_post_ids'])) {
146153
$sql->where('p.`id_prestablog_news` IN ' . "('" .
147-
implode("','", explode(",", preg_replace('/\s+/', ' ', $data['filter_post_ids']))) . "')");
154+
implode("','", explode(',', preg_replace('/\s+/', ' ', $data['filter_post_ids']))) . "')");
148155
}
149156

150157
if (!empty($data['filter_description']) && !empty($data['filter_name'])) {
151-
$sql->where("pnl.`title` = '%" . $data['filter_name'] . "%' OR pnl.content = '%" .
152-
$data['filter_description'] . "%' OR pnl.paragraph = '%" . $data['filter_description'] . "%'");
158+
$sql->where("pnl.`title` = '%" . pSQL($data['filter_name']) . "%' OR pnl.content = '%" .
159+
pSQL($data['filter_description']) . "%' OR pnl.paragraph = '%" . pSQL($data['filter_description']) . "%'");
153160
}
154161

155162
//tags are not yet implemented
156163

157164
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
165+
158166
return $result['count(*)'];
159167
}
160168

@@ -167,11 +175,12 @@ public function getNextPost($post_id)
167175
$sql->where('pn.`actif` = 1');
168176
$sql->where('pnl.`id_lang` = ' . (int) $this->context->language->id);
169177
$sql->orderBy('pn.date ASC');
170-
$sql->where("pn.id_prestablog_news > '" . (int)$post_id . "'");
178+
$sql->where("pn.id_prestablog_news > '" . (int) $post_id . "'");
171179
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
172180

173181
return $result;
174182
}
183+
175184
public function getPrevPost($post_id)
176185
{
177186
$sql = new DbQuery();
@@ -181,7 +190,7 @@ public function getPrevPost($post_id)
181190
$sql->where('pn.`actif` = 1');
182191
$sql->where('pnl.`id_lang` = ' . (int) $this->context->language->id);
183192
$sql->orderBy('pn.id_prestablog_news DESC');
184-
$sql->where("pn.id_prestablog_news < '" . (int)$post_id . "'");
193+
$sql->where("pn.id_prestablog_news < '" . (int) $post_id . "'");
185194

186195
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
187196

model/blog/url.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ public function link($params)
8989
$param += 1;
9090
}
9191
if (isset($params) && count($params) > 0 && !isset($params['rss'])) {
92+
9293
$ok_rewrite = $base_url_blog.'/'.$ok_rewrite_do.$ok_rewrite_categorie.$ok_rewrite_page;
9394
$ok_rewrite .= $ok_rewrite_year.$ok_rewrite_month.$ok_rewrite_titre.$ok_rewrite_seo;
9495
$ok_rewrite .= $ok_rewrite_cat.$ok_rewrite_id;
95-
9696
$ko_rewrite = '?fc=module&module=prestablog&controller=blog&'.ltrim(
9797
$ko_rewrite_do.$ko_rewrite_id.$ko_rewrite_cat.$ko_rewrite_page.$ko_rewrite_year.$ko_rewrite_month,
9898
'&'
@@ -114,11 +114,7 @@ public function link($params)
114114
(int)$params['id_lang'] = null;
115115
}
116116

117-
if ((int)Configuration::get('PS_REWRITING_SETTINGS') && (int)Configuration::get('prestablog_rewrite_actif')) {
118-
return $ok_rewrite;
119-
} else {
120-
return $ko_rewrite;
121-
}
117+
return $ok_rewrite;
122118
}
123119

124120
public function prestablogFilter($retourne)

model/common/address.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function getAddress($address_id)
1717
$sql = new DbQuery();
1818
$sql->select('*');
1919
$sql->from('address', 'a');
20-
$sql->where('a.`id_address` = '.$address_id);
20+
$sql->where('a.`id_address` = '.(int)$address_id);
2121

2222
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
2323

model/common/country.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getCountries($data)
4242
$sql->where('cl.`id_lang` = ' . (int) $this->context->language->id);
4343

4444
if (!empty($data['filter_name'])) {
45-
$sql->where("cl.`name` LIKE '%" . $data['filter_name']. "%'");
45+
$sql->where("cl.`name` LIKE '%" . pSQL($data['filter_name']). "%'");
4646
}
4747

4848
$sql->orderBy($sort . ' ' . $data['order']);
@@ -65,7 +65,7 @@ public function getTotalCountries($data)
6565
$sql->where('cl.`id_lang` = ' . (int) $this->context->language->id);
6666

6767
if (!empty($data['filter_name'])) {
68-
$sql->where("cl.`name` LIKE '%" . $data['filter_name']. "%'");
68+
$sql->where("cl.`name` LIKE '%" . pSQL($data['filter_name']). "%'");
6969
}
7070

7171

model/common/language.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function getLanguageByLocale($locale)
3131
$sql->from('lang', 'l');
3232
$sql->leftJoin('lang_shop', 'ls', 'ls.`id_lang` = l.`id_lang`');
3333
if (_PS_VERSION_ > '1.7.0.0') {
34-
$sql->where("LOWER(l.locale) LIKE '%".$locale."%'");
34+
$sql->where("LOWER(l.locale) LIKE '%".pSQL($locale)."%'");
3535
} else {
36-
$sql->where("LOWER(l.language_code) LIKE '%".$locale."%'");
36+
$sql->where("LOWER(l.language_code) LIKE '%".pSQL($locale)."%'");
3737
}
3838

3939

model/common/page.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ public function getPage($page_id)
3737
'title' => $page->meta_title,
3838
'description' => html_entity_decode($page->content, ENT_QUOTES, 'UTF-8'),
3939
'sort_order' => (int) $page->position,
40-
'keyword' => $url
40+
'keyword' => $url,
41+
'meta' => array(
42+
'title' => $page->meta_title,
43+
'description' => $page->meta_description,
44+
'keyword' => $page->meta_keywords,
45+
),
4146
);
4247
}
4348

@@ -64,9 +69,9 @@ public function getPages($data = array())
6469
$sql->where('cl.`id_lang` = ' . (int) $this->context->language->id);
6570

6671
if (!empty($data['filter_title']) && !empty($data['filter_description'])) {
67-
$sql->where("cl.`meta_title` = '%" . $data['filter_title'] .
68-
"%' OR cl.content = '%" . $data['filter_description'] .
69-
"%' OR cl.meta_description = '%" . $data['filter_description'] . "%'");
72+
$sql->where("cl.`meta_title` = '%" . pSQL($data['filter_title']) .
73+
"%' OR cl.content = '%" . pSQL($data['filter_description']) .
74+
"%' OR cl.meta_description = '%" . pSQL($data['filter_description']). "%'");
7075
}
7176

7277
$sql->orderBy($sort . ' ' . $data['order']);

model/common/zone.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public function getZones($data)
3636
$sql->from('state', 's');
3737

3838
if (!empty($data['filter_name'])) {
39-
$sql->where("s.`name` LIKE '%" . $data['filter_name']. "%'");
39+
$sql->where("s.`name` LIKE '%" . pSQL($data['filter_name']). "%'");
4040
}
4141

4242
if (!empty($data['filter_country_id'])) {
43-
$sql->where("s.`id_country` = " . $data['filter_country_id']. "");
43+
$sql->where("s.`id_country` = " . pSQL($data['filter_country_id']). "");
4444
}
4545

4646

@@ -61,11 +61,11 @@ public function getTotalZones($data)
6161
$sql->from('state', 's');
6262

6363
if (!empty($data['filter_name'])) {
64-
$sql->where("s.`name` LIKE '%" . $data['filter_name']. "%'");
64+
$sql->where("s.`name` LIKE '%" . pSQL($data['filter_name']). "%'");
6565
}
6666

6767
if (!empty($data['filter_country_id'])) {
68-
$sql->where("s.`id_country` = " . $data['filter_country_id']. "");
68+
$sql->where("s.`id_country` = " . pSQL($data['filter_country_id']). "");
6969
}
7070

7171
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);

model/store/category.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* @author VueFront
88
* @copyright Copyright (c) permanent, VueFront
99
* @license MIT
10+
*
1011
* @version 0.1.0
1112
*/
12-
1313
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
1414

1515
class ModelStoreCategory extends Model
@@ -71,7 +71,12 @@ public function getCategory($category_id)
7171
'parent_id' => $category->id_parent,
7272
'image' => $thumb,
7373
'imageLazy' => $thumbLazy,
74-
'keyword' => $url
74+
'keyword' => $url,
75+
'meta' => array(
76+
'title' => $category->meta_title,
77+
'description' => $category->meta_description,
78+
'keyword' => $category->meta_keywords,
79+
),
7580
);
7681
}
7782

@@ -103,7 +108,7 @@ public function getCategories($data = array())
103108
$sql->where('cl.`id_lang` = ' . (int) $this->context->language->id);
104109

105110
if ($parent_id) {
106-
$sql->where('c.`id_parent` = ' . $parent_id);
111+
$sql->where('c.`id_parent` = ' . (int)$parent_id);
107112
}
108113

109114
$sql->orderBy($sort . ' ' . $data['order']);
@@ -138,10 +143,11 @@ public function getTotalCategories($data = array())
138143
$sql->where('cl.`id_lang` = ' . (int) $language_id);
139144

140145
if ($parent_id) {
141-
$sql->where('c.`id_parent` = ' . $parent_id);
146+
$sql->where('c.`id_parent` = ' . (int)$parent_id);
142147
}
143148

144149
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
150+
145151
return $result['count(*)'];
146152
}
147153
}

0 commit comments

Comments
 (0)