* @copyright 2008-2015 Mediacom87 * @license define in the module * @version 1.7.0 */ class blockzopim extends Module { /** * __construct function. * * @access public * @return void */ public function __construct() { $this->name = 'blockzopim'; $this->tab = version_compare(_PS_VERSION_, '1.4.0.0', '>=') ? 'advertising_marketing' : 'Mediacom87'; $this->version = '1.7.0'; $this->need_instance = 0; $this->author = 'Mediacom87'; parent::__construct(); $this->displayName = $this->l('Block Zopim'); $this->description = $this->l('Integrate your Zopim script on your site.'); $this->affiliateurl = 'http://bit.ly/zopimaff'; if (version_compare(_PS_VERSION_, '1.6.0.0', '>=')) { $this->bootstrap = true; } if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) { $this->moduleList(); } } /** * install function. * * @access public * @return void */ function install() { $this->addAsTrusted(); if (!parent::install() || !$this->registerHook('footer') || !Configuration::updateValue('ZOPIM', '') || !Configuration::updateValue('MED_MODULES_LIST', true) || !Configuration::updateValue('MED_MODULE_TIME', 0)) return false; return true; } /** * uninstall function. * * @access public * @return void */ function uninstall() { if (!Configuration::deleteByName('ZOPIM') || !parent::uninstall() || !Configuration::deleteByName('MED_MODULE_TIME')) return false; return true; } /** * getContent function. * * @access public * @param string $tab (default: 'AdminModules') * @return void */ public function getContent($tab = 'AdminModules') { $output = ''; if (Tools::isSubmit('submitblockzopim')) { if (Configuration::updateValue('ZOPIM', Tools::getValue('zopimscript'))) { $output .= $this->displayConfirmation($this->l('Settings updated')); } } elseif (Tools::isSubmit('saveModule')) { if (Configuration::get('MED_MODULES_LIST') != Tools::getValue('MED_MODULES_LIST')) { if (is_file(_PS_ROOT_DIR_.self::CACHE_FILE_MUST_HAVE_MODULES_LIST)) { Tools::deleteFile(_PS_ROOT_DIR_.self::CACHE_FILE_MUST_HAVE_MODULES_LIST); Configuration::deleteByName('MED_MODULE_TIME'); } } if (Configuration::updateValue('MED_MODULES_LIST', Tools::getValue('MED_MODULES_LIST'))) { $output .= $this->displayConfirmation($this->l('Settings updated')); } } $output .= '

'.$this->displayName.'

'; return $output.$this->displayForm(); } /** * displayForm function. * * @access public * @return void */ public function displayForm() { $message = '

'.$this->l('If you want to customize the Chat window directly in the PrestaShop Backoffice and adapt its design by shop when you use the multi shop mode.').'

'.$this->l('Discover our enhanced version of this module.').'

'; return ' '.$this->panelHeading($this->l('Settings')).'

'.$this->l('To configure this module, after registering on').' ZOPIM, '.$this->l('get code to insert the script and find the ID of your site in bold red represent the example below. Enter the ID above.').'

<!--Start of Zopim Live Chat Script-->
<script type="text/javascript">
window.$zopim||(function(d,s){var z=$zopim=function(c){z._.push(c)},$=z.s=
d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set.
_.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute(\'charset\',\'utf-8\');
$.src=\'//v2.zopim.com/?Ls3s2zqg6mTq4laFyAfVeLkTVnK5YPHn\';z.t=+new Date;$.
type=\'text/javascript\';e.parentNode.insertBefore($,e)})(document,\'script\');
</script>
<!--End of Zopim Live Chat Script-->

'.$this->submitButton('submitblockzopim').'
'.$this->displayInfoMessage($message).' '.$this->panelEnding().' '.$this->panelHeading($this->l('Informations'), 'fa-info-circle').'

'.$this->l('Discover our other dev on:').'

PrestaToolbox '.$this->l('Or').' PrestaShop Addons

'.$this->displayPaypalButton('MDQZ82DZ8UEQQ').' '.$this->panelEnding().' '.$this->panelHeading($this->l('Ads'), 'fa-plus-square').'

'.$this->l('You can also support our agency by clicking the advertising below').'.

'.$this->displayGoogleAds('5753334670').'

'.$this->panelEnding().' '.$this->displayListModules(); } /** * hookFooter function. * * @access public * @param mixed $params * @return void */ function hookFooter($params) { global $smarty; $zopim = Configuration::get('ZOPIM'); if ($zopim) { $smarty->assign('zopim', $zopim); return $this->display(__FILE__, 'blockzopim.tpl'); } } /** * displayInfoMessage function. * * @access private * @param mixed $message * @return void */ private function displayInfoMessage($message) { return '
'.$message.'
'; } /** * addAsTrusted function. * * @access public * @return void */ public function addAsTrusted() { if (defined('self::CACHE_FILE_TRUSTED_MODULES_LIST') == true) { if (isset($this->context->controller->controller_name) && $this->context->controller->controller_name == 'AdminModules') { $sxe = new SimpleXMLElement(''); $modules = $sxe->addChild('modules'); $module = $modules->addChild('module'); $module->addAttribute('action', 'install'); $module->addAttribute('name', $this->name); $trusted = $sxe->saveXML(); file_put_contents(_PS_ROOT_DIR_ . '/config/xml/themes/' . $this->name . '.xml', $trusted); if (is_file(_PS_ROOT_DIR_ . Module::CACHE_FILE_UNTRUSTED_MODULES_LIST)) { Tools::deleteFile(_PS_ROOT_DIR_ . Module::CACHE_FILE_UNTRUSTED_MODULES_LIST); } } } } /** * displayListModules function. * * @access private * @return void */ private function displayListModules() { if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) { return $this->panelHeading($this->l('Listing Modules')).'
'.$this->radioButton('MED_MODULES_LIST', $this->l('Yes'), $this->l('No')).'
'.$this->submitButton('saveModule').'
'.$this->panelEnding(); } } /** * displayPaypalButton function. * * @access private * @param mixed $id * @return void */ private function displayPaypalButton($id) { return '

'; } /** * displayGoogleAds function. * * @access private * @param mixed $slot * @return void */ private function displayGoogleAds($slot) { return ' '; } /** * panelHeading function. * * @access private * @param mixed $title * @param string $icon (default: 'fa-cog') * @return void */ private function panelHeading($title, $icon = 'fa-cog') { if (version_compare(_PS_VERSION_, '1.6.0.0', '<')) { return '
'.$title.''; } else { return '
'.$title.'
'; } } /** * moduleList function. * * @access private * @return void */ private function moduleList() { $conf = Configuration::getMultiple(array('MED_MODULES_LIST', 'MED_MODULE_TIME')); if (isset($conf['MED_MODULES_LIST']) && $conf['MED_MODULES_LIST']) { $time = time() - (23 * 60 * 60); if ($time > $conf['MED_MODULE_TIME']) { $must_have_content = Tools::file_get_contents('http://xml-feed.mediacom87.netdna-cdn.com/'.$this->isoCode().'/must_have_modules_list.xml'); $must_have_file = _PS_ROOT_DIR_.self::CACHE_FILE_MUST_HAVE_MODULES_LIST; if (file_put_contents($must_have_file, $must_have_content)) { Configuration::updateValue('MED_MODULE_TIME', time()); } } } } /** * panelEnding function. * * @access private * @return void */ private function panelEnding() { if (version_compare(_PS_VERSION_, '1.6.0.0', '>=')) { return '
'; } else { return '
'; } } /** * submitButton function. * * @access private * @param string $name (default: 'save') * @return void */ private function submitButton($name = 'save') { if (version_compare(_PS_VERSION_, '1.6.0.0', '<')) { return '

'; } else { return ''; } } /** * isoCode function. * * @access private * @param bool $domain (default: false) * @return void */ private function isoCode($domain = false) { if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) { global $cookie; $language = new Language($cookie->id_lang); $iso = $language->iso_code; } else { $iso = $this->context->language->iso_code; } if ($iso == 'fr') { return 'fr'; } else if ($domain) { return 'com'; } else { return 'en'; } } /** * radioButton function. * * @access private * @param mixed $sauv * @param mixed $ok * @param mixed $ko * @return void */ private function radioButton($sauv, $ok, $ko) { $result = Configuration::get($sauv); if (!isset($result)) { $result = 0; } if (version_compare(_PS_VERSION_, '1.6.0.0', '<')) { return ' '; } else { return ' '; } } }