2121 * @author VueFront
2222 * @copyright Copyright (c) permanent, VueFront
2323 * @license MIT
24+ *
2425 * @version 0.1.0
2526 */
26-
2727include_once _PS_MODULE_DIR_ . 'prestablog/class/news.class.php ' ;
2828
2929class 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
0 commit comments