PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/blockadvertising/blockadvertising.php

https://gitlab.com/sanjitbauli1/fedexcollection
PHP | 234 lines | 140 code | 31 blank | 63 comment | 17 complexity | e4fca326157f7d6ddfb384d934f6623e MD5 | raw file
  1. <?php
  2. /*
  3. * 2007-2012 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Academic Free License (AFL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/afl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@prestashop.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. * @author PrestaShop SA <contact@prestashop.com>
  22. * @copyright 2007-2012 PrestaShop SA
  23. * @version Release: $Revision: 14011 $
  24. * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
  25. * International Registered Trademark & Property of PrestaShop SA
  26. */
  27. if (!defined('_PS_VERSION_'))
  28. exit;
  29. class BlockAdvertising extends Module
  30. {
  31. public $adv_link;
  32. /**
  33. * adv_title contains string for title and alt attributes
  34. *
  35. * @var mixed
  36. */
  37. public $adv_title;
  38. /**
  39. * adv_img contains url to the image to display.
  40. *
  41. * @var mixed
  42. */
  43. public $adv_img;
  44. /**
  45. * adv_imgname is the filename of the image to display
  46. * @TODO make it configurable for SEO, but need a function to clean filename
  47. * @var string
  48. */
  49. public $adv_imgname = 'advertising_custom';
  50. public function __construct()
  51. {
  52. $this->name = 'blockadvertising';
  53. $this->tab = 'advertising_marketing';
  54. $this->version = 0.3;
  55. $this->author = 'PrestaShop';
  56. $this->need_instance = 0;
  57. parent::__construct();
  58. $this->displayName = $this->l('Block advertising');
  59. $this->description = $this->l('Adds a block to display an advertisement.');
  60. if (!file_exists(_PS_MODULE_DIR_.$this->name.'/'.$this->adv_imgname.'.'.Configuration::get('BLOCKADVERT_IMG_EXT')))
  61. {
  62. $this->adv_imgname = 'advertising';
  63. if (!file_exists(_PS_MODULE_DIR_.$this->name.'/advertising.jpg'))
  64. $this->adv_imgname = '';
  65. else
  66. Configuration::updateValue('BLOCKADVERT_IMG_EXT','jpg');
  67. }
  68. if (!empty($this->adv_imgname))
  69. $this->adv_img = Tools::getMediaServer($this->name)._MODULE_DIR_.$this->name.'/'.$this->adv_imgname.'.'.Configuration::get('BLOCKADVERT_IMG_EXT');
  70. $this->adv_link = htmlentities(Configuration::get('BLOCKADVERT_LINK'), ENT_QUOTES, 'UTF-8');
  71. $this->adv_title = htmlentities(Configuration::get('BLOCKADVERT_TITLE'), ENT_QUOTES, 'UTF-8');
  72. }
  73. public function install()
  74. {
  75. Configuration::updateValue('BLOCKADVERT_LINK', 'http://www.prestashop.com');
  76. if (!parent::install())
  77. return false;
  78. if (!$this->registerHook('leftColumn') OR !$this->registerHook('rightColumn'))
  79. return false;
  80. return true;
  81. }
  82. /**
  83. * _deleteCurrentImg delete current image, (so this will use default image)
  84. *
  85. * @return void
  86. */
  87. private function _deleteCurrentImg()
  88. {
  89. if (file_exists(_PS_MODULE_DIR_.$this->name.'/'.$this->adv_imgname.'.'.Configuration::get('BLOCKADVERT_IMG_EXT')))
  90. unlink(_PS_MODULE_DIR_.$this->name.'/'.$this->adv_imgname.'.'.Configuration::get('BLOCKADVERT_IMG_EXT'));
  91. $this->adv_imgname = $this->adv_imgname == 'advertising_custom'?'advertising':'';
  92. }
  93. /**
  94. * postProcess update configuration
  95. * @TODO adding alt and title attributes for <img> and <a>
  96. * @var string
  97. * @return void
  98. */
  99. public function postProcess()
  100. {
  101. global $currentIndex;
  102. $errors = '';
  103. if (Tools::isSubmit('submitDeleteImgConf'))
  104. $this->_deleteCurrentImg();
  105. if (Tools::isSubmit('submitAdvConf'))
  106. {
  107. $file = false;
  108. if (isset($_FILES['adv_img']) AND isset($_FILES['adv_img']['tmp_name']) AND !empty($_FILES['adv_img']['tmp_name']))
  109. {
  110. if ($error = checkImage($_FILES['adv_img'], Tools::convertBytes(ini_get('upload_max_filesize'))))
  111. $errors .= $error;
  112. elseif ($dot_pos = strrpos($_FILES['adv_img']['name'],'.'))
  113. {
  114. // as checkImage tell us it's a good image, we'll just copy the extension
  115. $this->_deleteCurrentImg();
  116. $this->adv_imgname = 'advertising';
  117. $ext = substr($_FILES['adv_img']['name'], $dot_pos+1);
  118. $newname = 'advertising_custom';
  119. if (!move_uploaded_file($_FILES['adv_img']['tmp_name'],_PS_MODULE_DIR_.$this->name.'/'.$newname.'.'.$ext))
  120. $errors .= $this->l('Error move uploaded file');
  121. else
  122. $this->adv_imgname = $newname;
  123. Configuration::updateValue('BLOCKADVERT_IMG_EXT',$ext);
  124. $this->adv_img = Tools::getMediaServer($this->name)._MODULE_DIR_.$this->name.'/'.$this->adv_imgname.'.'.Configuration::get('BLOCKADVERT_IMG_EXT');
  125. }
  126. }
  127. if ($link = Tools::getValue('adv_link'))
  128. {
  129. Configuration::updateValue('BLOCKADVERT_LINK', $link);
  130. $this->adv_link = htmlentities($link, ENT_QUOTES, 'UTF-8');
  131. }
  132. if ($title = Tools::getValue('adv_title'))
  133. {
  134. Configuration::updateValue('BLOCKADVERT_TITLE', $title);
  135. $this->adv_title = htmlentities($title, ENT_QUOTES, 'UTF-8');
  136. }
  137. }
  138. if ($errors)
  139. echo $this->displayError($errors);
  140. }
  141. /**
  142. * getContent used to display admin module form
  143. *
  144. * @return void
  145. */
  146. public function getContent()
  147. {
  148. global $protocol_content;
  149. $this->postProcess();
  150. $output = '';
  151. $output .= '
  152. <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">
  153. <fieldset><legend>'.$this->l('Advertising block configuration').'</legend>
  154. <a href="'.$this->adv_link.'" target="_blank" title="'.$this->adv_title.'">';
  155. if ($this->adv_img)
  156. {
  157. $output .= '<img src="'.$protocol_content.$this->adv_img.'" alt="'.$this->adv_title.'" title="'.$this->adv_title.'" style="height:163px;margin-left: 100px;width:163px"/>';
  158. $output .= '<input class="button" type="submit" name="submitDeleteImgConf" value="'.$this->l('Delete image').'" style=""/>';
  159. }
  160. else
  161. $output .= '<div style="margin-left: 100px;width:163px;">'.$this->l('no image').'</div>';
  162. $output .= '</a>';
  163. $output .= '<br/>
  164. <br/>
  165. <label for="adv_img">'.$this->l('Change image').'&nbsp;&nbsp;</label><input id="adv_img" type="file" name="adv_img" />
  166. ( '.$this->l('Image will be displayed as 155x163').' )
  167. <br/>
  168. <br class="clear"/>
  169. <label for="adv_link">'.$this->l('Image link').'&nbsp;&nbsp;</label><input id="adv_link" type="text" name="adv_link" value="'.$this->adv_link.'" />
  170. <br class="clear"/>
  171. <br/>
  172. <label for="adv_title">'.$this->l('Title').'&nbsp;&nbsp;</label><input id="adv_title" type="text" name="adv_title" value="'.$this->adv_title.'" />
  173. <br class="clear"/>
  174. <br/>
  175. <input class="button" type="submit" name="submitAdvConf" value="'.$this->l('validate').'" style="margin-left: 200px;"/>
  176. </fieldset>
  177. </form>
  178. ';
  179. return $output;
  180. }
  181. /**
  182. * Returns module content
  183. *
  184. * @param array $params Parameters
  185. * @return string Content
  186. */
  187. public function hookRightColumn($params)
  188. {
  189. global $smarty, $protocol_content;
  190. $smarty->assign('image', $protocol_content.$this->adv_img);
  191. $smarty->assign('adv_link', $this->adv_link);
  192. $smarty->assign('adv_title', $this->adv_title);
  193. return $this->display(__FILE__, 'blockadvertising.tpl');
  194. }
  195. public function hookLeftColumn($params)
  196. {
  197. return $this->hookRightColumn($params);
  198. }
  199. public function hookHeader($params)
  200. {
  201. Tools::addCSS($this->_path.'blockadvertising.css', 'all');
  202. }
  203. }