Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.85 KB | None | 0 0
  1. <?php
  2. /**
  3. * Powerful Form Generator
  4. *
  5. * This modules aims to provide for your customer any kind of form you want.
  6. *
  7. * If you find errors, bugs or if you want to share some improvments,
  8. * feel free to contact at contact@prestaddons.net ! :)
  9. * Si vous trouvez des erreurs, des bugs ou si vous souhaitez
  10. * tout simplement partager un conseil ou une amélioration,
  11. * n'hésitez pas à me contacter à contact@prestaddons.net
  12. *
  13. * @package modules
  14. * @author Cyril Nicodème <contact@prestaddons.net>
  15. * @copyright Copyright (C) April 2014 prestaddons.net <@email:contact@prestaddons.net>. All rights reserved.
  16. * @since 2014-04-15
  17. * @version 2.7.2
  18. * @license Nicodème Cyril
  19. */
  20. require_once(_PS_MODULE_DIR_.'powerfulformgenerator/classes/PFGRenderer.php');
  21. class CmsController extends CmsControllerCore
  22. {
  23. /*
  24. * module: powerfulformgenerator
  25. * date: 2017-04-21 20:54:49
  26. * version: 2.7.2
  27. */
  28.  
  29. public function setMedia()
  30. {
  31. parent::setMedia();
  32. if ($this->assignCase == 1)
  33. {
  34. $this->addJS(_THEME_JS_DIR_ . 'cms.js');
  35. }
  36. $this->addCSS(_THEME_CSS_DIR_ . 'product_list.css');
  37. $this->addCSS(_THEME_CSS_DIR_ . 'cms.css');
  38. $this->addCSS(_PS_MODULE_DIR_ . 'cmsproducts/cmsproducts.css');
  39. }
  40.  
  41.  
  42. public function initContent()
  43. {
  44. parent::initContent();
  45. $parent_cat = new CMSCategory(1, $this->context->language->id);
  46. $this->context->smarty->assign('id_current_lang', $this->context->language->id);
  47. $this->context->smarty->assign('home_title', $parent_cat->name);
  48. $this->context->smarty->assign('cgv_id', Configuration::get('PS_CONDITIONS_CMS_ID'));
  49. if ($this->assignCase == 1) {
  50. if ($this->cms->indexation == 0) {
  51. $this->context->smarty->assign('nobots', true);
  52. }
  53. if (version_compare(Tools::substr(_PS_VERSION_, 0, 3), '1.7', '>=')) {
  54. $currentCms = $this->objectPresenter->present($this->cms);
  55. $currentCms['content'] = $this->returnContent($currentCms['content']);
  56. $this->context->smarty->assign(array(
  57. 'cms' => $currentCms,
  58. ));
  59. $this->setTemplate(
  60. 'cms/page',
  61. array('entity' => 'cms', 'id' => $this->cms->id)
  62. );
  63. } else {
  64. if (isset($this->cms->id_cms_category) && $this->cms->id_cms_category) {
  65. $path = Tools::getFullPath($this->cms->id_cms_category, $this->cms->meta_title, 'CMS');
  66. } elseif (isset($this->cms_category->meta_title)) {
  67. $path = Tools::getFullPath(1, $this->cms_category->meta_title, 'CMS');
  68. }
  69. $this->cms->content = $this->returnContent($this->cms->content);
  70. $this->context->smarty->assign(array(
  71. 'cms' => $this->cms,
  72. 'content_only' => (int)Tools::getValue('content_only'),
  73. 'path' => $path,
  74. 'body_classes' => array($this->php_self.'-'.$this->cms->id, $this->php_self.'-'.$this->cms->link_rewrite)
  75. ));
  76. $this->setTemplate(_PS_THEME_DIR_.'cms.tpl');
  77. }
  78. } elseif ($this->assignCase == 2) {
  79. if (version_compare(Tools::substr(_PS_VERSION_, 0, 3), '1.7', '>=')) {
  80. $this->context->smarty->assign($this->getTemplateVarCategoryCms());
  81. $this->setTemplate('cms/category');
  82. } else {
  83. $this->context->smarty->assign(array(
  84. 'category' => $this->cms_category, //for backward compatibility
  85. 'cms_category' => $this->cms_category,
  86. 'sub_category' => $this->cms_category->getSubCategories($this->context->language->id),
  87. 'cms_pages' => CMS::getCMSPages($this->context->language->id, (int)$this->cms_category->id, true, (int)$this->context->shop->id),
  88. 'path' => ($this->cms_category->id !== 1) ? Tools::getPath($this->cms_category->id, $this->cms_category->name, false, 'CMS') : '',
  89. 'body_classes' => array($this->php_self.'-'.$this->cms_category->id, $this->php_self.'-'.$this->cms_category->link_rewrite)
  90. ));
  91. $this->setTemplate(_PS_THEME_DIR_.'cms.tpl');
  92. }
  93. }
  94. }
  95. /*
  96. * module: powerfulformgenerator
  97. * date: 2017-04-21 20:54:49
  98. * version: 2.7.2
  99. */
  100. private function generatePFG($id_pfg)
  101. {
  102. $renderer = new PFGRenderer($id_pfg);
  103. if (!$renderer->isAllowed(true)) {
  104. $redirect_url = $renderer->getForm()->unauth_redirect_url[Context::getContext()->language->id];
  105. if (!empty($redirect_url)) {
  106. Tools::redirect($redirect_url);
  107. } else {
  108. Controller::getController('PageNotFoundController')->run();
  109. }
  110. exit();
  111. }
  112. return $renderer->displayForm();
  113. }
  114. /*
  115. * module: powerfulformgenerator
  116. * date: 2017-04-21 20:54:49
  117. * version: 2.7.2
  118. */
  119. public function returnContent($contents)
  120. {
  121. preg_match_all('/\{powerfulform\:[(0-9\,)]+\}/i', $contents, $matches);
  122. foreach ($matches[0] as $index => $match) {
  123. $explode = explode(":", $match);
  124. $contents = str_replace($match, $this->generatePFG(str_replace("}", "", $explode[1])), $contents);
  125. }
  126. /** PRODUCTS **/
  127. preg_match_all('/\{products\:[(0-9\,)]+\}/i', $contents, $matches);
  128. foreach ($matches[0] as $index => $match)
  129. {
  130. $explode = explode(":", $match);
  131. $contents = str_replace($match, $this->returnProducts(str_replace("}", "", $explode[1])), $contents);
  132. }
  133.  
  134. /** PRODUCT **/
  135. preg_match_all('/\{product\:[(0-9\,)]+\}/i', $contents, $matches);
  136. foreach ($matches[0] as $index => $match)
  137. {
  138. $explode = explode(":", $match);
  139. $contents = str_replace($match, $this->returnProduct(str_replace("}", "", $explode[1])), $contents);
  140. }
  141.  
  142. /** HOMEPAGE PRODUCTS PRO FEED **/
  143. preg_match_all('/\{hpp\:[(0-9)]+\}/i', $contents, $matches);
  144. foreach ($matches[0] as $index => $match)
  145. {
  146. $explode = explode(":", $match);
  147. $contents = str_replace($match, $this->returnProductsHpp(str_replace("}", "", $explode[1])), $contents);
  148. }
  149.  
  150. /** RELATED PRODUCTS PRO FEED **/
  151. preg_match_all('/\{rpp\:[(0-9)]+\}/i', $contents, $matches);
  152. foreach ($matches[0] as $index => $match)
  153. {
  154. $explode = explode(":", $match);
  155. $contents = str_replace($match, $this->returnProductsRpp(str_replace("}", "", $explode[1])), $contents);
  156. }
  157. return $contents;
  158. }
  159.  
  160.  
  161. public static function getImagesByID($id_product, $limit = 0)
  162. {
  163. $id_image = Db::getInstance()->ExecuteS('SELECT `id_image` FROM `' . _DB_PREFIX_ . 'image` WHERE cover=1 AND `id_product` = ' . (int)$id_product . ' ORDER BY position ASC LIMIT 0, ' . (int)$limit);
  164. $toReturn = array();
  165. if (!$id_image)
  166. {
  167. return null;
  168. }
  169. else
  170. {
  171. foreach ($id_image as $image)
  172. {
  173. $toReturn[] = $id_product . '-' . $image['id_image'];
  174. }
  175. }
  176. return $toReturn;
  177. }
  178.  
  179. public function returnProduct($id_product)
  180. {
  181. $explode[] = $id_product;
  182. foreach ($explode as $tproduct)
  183. {
  184. if ($tproduct != '')
  185. {
  186. $x = (array)new Product($tproduct, true, $this->context->language->id);
  187. $productss[$tproduct] = $x;
  188. $productss[$tproduct]['id_product'] = $tproduct;
  189. $image = self::getImagesByID($tproduct, 1);
  190. $picture = explode('-', $image[0]);
  191. $productss[$tproduct]['id_image'] = $picture[1];
  192.  
  193. }
  194. }
  195. $products = Product::getProductsProperties($this->context->language->id, $productss);
  196. $this->context->smarty->assign('products', $products);
  197. $this->context->smarty->assign('feedtype', "cmsSingleProductFeed");
  198. $contents = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'cmsproducts/products.tpl');
  199. return $contents;
  200. }
  201.  
  202. public function returnProducts($id_product)
  203. {
  204. $explode_products = explode(",", $id_product);
  205. foreach ($explode_products AS $idp)
  206. {
  207. $explode[] = $idp;
  208. foreach ($explode as $tproduct)
  209. {
  210. if ($tproduct != '')
  211. {
  212. $x = (array)new Product($tproduct, true, $this->context->language->id);
  213. $productss[$tproduct] = $x;
  214. $productss[$tproduct]['id_product'] = $tproduct;
  215. $image = self::getImagesByID($tproduct, 1);
  216. $picture = explode('-', $image[0]);
  217. $productss[$tproduct]['id_image'] = $picture[1];
  218.  
  219. }
  220. }
  221. }
  222. $products = Product::getProductsProperties($this->context->language->id, $productss);
  223. $this->context->smarty->assign('products', $products);
  224. $this->context->smarty->assign('feedtype', "cmsProductsFeed");
  225. $contents = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'cmsproducts/products.tpl');
  226. return $contents;
  227. }
  228.  
  229. public function returnProductsHpp($block)
  230. {
  231. if (class_exists("Hpp"))
  232. {
  233. $hpp = new Hpp();
  234. if (method_exists($hpp, 'returnProducts'))
  235. {
  236. return $this->displayHpp($hpp->returnProducts($block));
  237. }
  238. else
  239. {
  240. return $this->noModuleMessage("Homepage Products Pro");
  241. }
  242. }
  243. else
  244. {
  245. return $this->noModuleMessage("Homepage Products Pro");
  246. }
  247. }
  248.  
  249. public function returnProductsRpp($block)
  250. {
  251. if (class_exists("Ppb"))
  252. {
  253. $rpp = new Ppb();
  254. if (method_exists($rpp, 'returnProducts'))
  255. {
  256. return $this->displayRpp($rpp->returnProducts($block));
  257. }
  258. else
  259. {
  260. return $this->noModuleMessage("Related Products Pro");
  261. }
  262. }
  263. else
  264. {
  265. return $this->noModuleMessage("Related Products Pro");
  266. }
  267. }
  268.  
  269. public function displayRpp($products)
  270. {
  271. if (count($products) <= 0)
  272. {
  273. $this->context->smarty->assign('feedtype', "noProducts");
  274. }
  275. else
  276. {
  277. $this->context->smarty->assign('products', $products);
  278. $this->context->smarty->assign('feedtype', "rppfeed");
  279. }
  280. $contents = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'cmsproducts/products.tpl');
  281. return $contents;
  282. }
  283.  
  284. public function displayHpp($products)
  285. {
  286. if (count($products) <= 0)
  287. {
  288. $this->context->smarty->assign('feedtype', "noProducts");
  289. }
  290. else
  291. {
  292. $this->context->smarty->assign('products', $products);
  293. $this->context->smarty->assign('feedtype', "hppfeed");
  294. }
  295. $contents = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'cmsproducts/products.tpl');
  296. return $contents;
  297. }
  298.  
  299. public function noModuleMessage($module)
  300. {
  301. $this->context->smarty->assign('products', $products);
  302. $this->context->smarty->assign('module', $module);
  303. $this->context->smarty->assign('feedtype', "error");
  304. $contents = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'cmsproducts/products.tpl');
  305. return $contents;
  306. }
  307.  
  308. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement