PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/blockfacebook/blockfacebook.php

https://gitlab.com/staging06/myproject
PHP | 170 lines | 126 code | 18 blank | 26 comment | 10 complexity | ff2d26c9742191e8be51f699403fef46 MD5 | raw file
  1. <?php
  2. /*
  3. * 2007-2015 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-2015 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 BlockFacebook extends Module
  29. {
  30. public function __construct()
  31. {
  32. $this->name = 'blockfacebook';
  33. $this->tab = 'front_office_features';
  34. $this->version = '1.4.0';
  35. $this->author = 'PrestaShop';
  36. $this->bootstrap = true;
  37. parent::__construct();
  38. $this->displayName = $this->l('Facebook Like Box block');
  39. $this->description = $this->l('Displays a block for subscribing to your Facebook Page.');
  40. $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
  41. }
  42. public function install()
  43. {
  44. return parent::install() &&
  45. Configuration::updateValue('blockfacebook_url', 'https://www.facebook.com/prestashop') &&
  46. $this->registerHook('displayHome') &&
  47. $this->registerHook('displayHeader');
  48. }
  49. public function uninstall()
  50. {
  51. // Delete configuration
  52. return Configuration::deleteByName('blockfacebook_url') && parent::uninstall();
  53. }
  54. public function getContent()
  55. {
  56. $html = '';
  57. // If we try to update the settings
  58. if (Tools::isSubmit('submitModule'))
  59. {
  60. Configuration::updateValue('blockfacebook_url', Tools::getValue('blockfacebook_url'));
  61. $html .= $this->displayConfirmation($this->l('Configuration updated'));
  62. $this->_clearCache('blockfacebook.tpl');
  63. Tools::redirectAdmin('index.php?tab=AdminModules&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'));
  64. }
  65. $html .= $this->renderForm();
  66. $facebookurl = Configuration::get('blockfacebook_url');
  67. if(!strstr($facebookurl, "facebook.com")) $facebookurl="https://www.facebook.com/".$facebookurl;
  68. $this->context->smarty->assign('facebookurl', $facebookurl);
  69. $this->context->smarty->assign('facebook_js_url', $this->_path.'blockfacebook.js');
  70. $this->context->smarty->assign('facebook_css_url', $this->_path.'css/blockfacebook.css');
  71. $html .= $this->context->smarty->fetch($this->local_path.'views/admin/_configure/preview.tpl');
  72. return $html;
  73. }
  74. public function hookDisplayHome()
  75. {
  76. if (!$this->isCached('blockfacebook.tpl', $this->getCacheId()))
  77. {
  78. $facebookurl = Configuration::get('blockfacebook_url');
  79. if (!strstr($facebookurl, 'facebook.com'))
  80. $facebookurl = 'https://www.facebook.com/'.$facebookurl;
  81. $this->context->smarty->assign('facebookurl', $facebookurl);
  82. }
  83. return $this->display(__FILE__, 'blockfacebook.tpl', $this->getCacheId());
  84. }
  85. public function hookDisplayLeftColumn()
  86. {
  87. if ($this->page_name !== 'index')
  88. $this->_assignMedia();
  89. return $this->hookDisplayHome();
  90. }
  91. public function hookDisplayRightColumn()
  92. {
  93. if ($this->page_name !== 'index')
  94. $this->_assignMedia();
  95. return $this->hookDisplayHome();
  96. }
  97. public function hookHeader()
  98. {
  99. $this->page_name = Dispatcher::getInstance()->getController();
  100. if ($this->page_name == 'index')
  101. $this->_assignMedia();
  102. }
  103. protected function _assignMedia()
  104. {
  105. $this->context->controller->addCss(($this->_path).'css/blockfacebook.css');
  106. $this->context->controller->addJS(($this->_path).'blockfacebook.js');
  107. }
  108. public function renderForm()
  109. {
  110. $fields_form = array(
  111. 'form' => array(
  112. 'legend' => array(
  113. 'title' => $this->l('Settings'),
  114. 'icon' => 'icon-cogs'
  115. ),
  116. 'input' => array(
  117. array(
  118. 'type' => 'text',
  119. 'label' => $this->l('Facebook link (full URL is required)'),
  120. 'name' => 'blockfacebook_url',
  121. ),
  122. ),
  123. 'submit' => array(
  124. 'title' => $this->l('Save')
  125. )
  126. ),
  127. );
  128. $helper = new HelperForm();
  129. $helper->show_toolbar = false;
  130. $helper->table = $this->table;
  131. $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
  132. $helper->default_form_language = $lang->id;
  133. $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
  134. $this->fields_form = array();
  135. $helper->identifier = $this->identifier;
  136. $helper->submit_action = 'submitModule';
  137. $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
  138. $helper->token = Tools::getAdminTokenLite('AdminModules');
  139. $helper->tpl_vars = array(
  140. 'fields_value' => $this->getConfigFieldsValues(),
  141. 'languages' => $this->context->controller->getLanguages(),
  142. 'id_language' => $this->context->language->id
  143. );
  144. return $helper->generateForm(array($fields_form));
  145. }
  146. public function getConfigFieldsValues()
  147. {
  148. return array(
  149. 'blockfacebook_url' => Tools::getValue('blockfacebook_url', Configuration::get('blockfacebook_url')),
  150. );
  151. }
  152. }