PageRenderTime 60ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/admin5513/autoupgrade/latest/prestashop/modules/blockstore/blockstore.php

https://bitbucket.org/marketing_alfatec/colette
PHP | 136 lines | 98 code | 14 blank | 24 comment | 15 complexity | 18f6d42630b3be40094d1cb33b79c452 MD5 | raw file
  1. <?php
  2. /*
  3. * 2007-2013 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-2013 PrestaShop SA
  23. * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
  24. * International Registered Trademark & Property of PrestaShop SA
  25. */
  26. if (!defined('_PS_VERSION_'))
  27. exit;
  28. class BlockStore extends Module
  29. {
  30. public function __construct()
  31. {
  32. $this->name = 'blockstore';
  33. $this->tab = 'front_office_features';
  34. $this->version = 1.0;
  35. $this->author = 'PrestaShop';
  36. $this->need_instance = 0;
  37. parent::__construct();
  38. $this->displayName = $this->l('Store locator block');
  39. $this->description = $this->l('Displays a store locator link directly on your webiste.');
  40. }
  41. public function install()
  42. {
  43. Configuration::updateValue('BLOCKSTORE_IMG', 'store.jpg');
  44. return parent::install() && $this->registerHook('rightColumn') && $this->registerHook('header');
  45. }
  46. public function uninstall()
  47. {
  48. Configuration::deleteByName('BLOCKSTORE_IMG');
  49. return parent::uninstall();
  50. }
  51. public function hookLeftColumn($params)
  52. {
  53. return $this->hookRightColumn($params);
  54. }
  55. public function hookRightColumn($params)
  56. {
  57. if (!$this->isCached('blockstore.tpl', $this->getCacheId()))
  58. {
  59. $this->smarty->assign('store_img', Configuration::get('BLOCKSTORE_IMG'));
  60. $sql = 'SELECT COUNT(*)
  61. FROM '._DB_PREFIX_.'store s'
  62. .Shop::addSqlAssociation('store', 's');
  63. $total = Db::getInstance()->getValue($sql);
  64. if ($total <= 0)
  65. return;
  66. }
  67. return $this->display(__FILE__, 'blockstore.tpl', $this->getCacheId());
  68. }
  69. public function hookHeader($params)
  70. {
  71. $this->context->controller->addCSS($this->_path.'blockstore.css', 'all');
  72. }
  73. public function postProcess()
  74. {
  75. if (Tools::isSubmit('submitStoreConf'))
  76. {
  77. if (isset($_FILES['store_img']) && isset($_FILES['store_img']['tmp_name']) && !empty($_FILES['store_img']['tmp_name']))
  78. {
  79. if ($error = ImageManager::validateUpload($_FILES['store_img'], 4000000))
  80. return $this->displayError($this->l('Invalid image'));
  81. else
  82. {
  83. $ext = substr($_FILES['store_img']['name'], strrpos($_FILES['store_img']['name'], '.') + 1);
  84. $file_name = md5($_FILES['store_img']['name']).'.'.$ext;
  85. if (!move_uploaded_file($_FILES['store_img']['tmp_name'], dirname(__FILE__).'/'.$file_name))
  86. return $this->displayError($this->l('An error occurred while attempting to upload the file.'));
  87. else
  88. {
  89. if (Configuration::hasContext('BLOCKSTORE_IMG', null, Shop::getContext()) && Configuration::get('BLOCKSTORE_IMG') != $file_name)
  90. @unlink(dirname(__FILE__).'/'.Configuration::get('BLOCKSTORE_IMG'));
  91. Configuration::updateValue('BLOCKSTORE_IMG', $file_name);
  92. $this->_clearCache('blockstore.tpl');
  93. return $this->displayConfirmation($this->l('The settings have been updated.'));
  94. }
  95. }
  96. }
  97. }
  98. return '';
  99. }
  100. public function getContent()
  101. {
  102. $output = $this->postProcess().'
  103. <form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">
  104. <fieldset>
  105. <legend>'.$this->l('Store locator block configuration').'</legend>';
  106. if (Configuration::get('BLOCKSTORE_IMG'))
  107. $output .= '<div class="margin-form"><img src="'.Tools::getProtocol().Tools::getMediaServer($this->name)._MODULE_DIR_.$this->name.'/'.Configuration::get('BLOCKSTORE_IMG').'" alt="'.$this->l('Store image').'" style="height:115px;margin-left: 100px;width:174px"/></div>';
  108. $output .= '
  109. <label for="store_img">'.$this->l('Change image').'</label>
  110. <div class="margin-form">
  111. <input id="store_img" type="file" name="store_img" /> ( '.$this->l('The selected image will be displayed as 174x115').' )
  112. </div>
  113. <p class="center">
  114. <input class="button" type="submit" name="submitStoreConf" value="'.$this->l('Save').'"/>
  115. </p>
  116. </fieldset>
  117. </form>
  118. ';
  119. return $output;
  120. }
  121. }