public function ajaxProcessInfoQuery() { $this->content_only = true; $result = array('status' => false); if (time() > (int) Configuration::get('PP_INFO_CHECK_TIME')) { $protocol = Tools::getCurrentUrlProtocolPrefix(); $iso_lang = Context::getContext()->language->iso_code; $iso_country = Context::getContext()->country->iso_code; $stream_context = @stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 3))); $old_content = $this->getInfo(); $msg = $old_content === false ? 0 : $old_content[0]; $shop_url = ShopUrl::getShopUrls($this->context->shop->id)->where('main', '=', 1)->getFirst(); $shop = $shop_url ? $shop_url->getURL() : Tools::getShopDomain(); $date = Db::getInstance()->getValue('SELECT `date_add` FROM `' . _DB_PREFIX_ . 'configuration` WHERE `name` = \'PSM_ID_' . Tools::strtoupper($this->module->name) . '\''); $psm_date = $date ? urlencode(date('Y-m-d H:i:s', strtotime($date))) : ''; $plugins_string = ''; $plugins = $this->module->plugins(); foreach ($plugins as $name => $api_version) { if (Module::isInstalled($name)) { $plugins_string .= '&' . $name . '=' . $this->moduleVersion($name); } } $url = $protocol . 'store.psandmore.com/query/?key=' . $this->module->name . '&ver=' . $this->module->version . '&psm=' . PSM::getPSMId($this->module) . '&psm_date=' . $psm_date . $plugins_string . '&msg=' . $msg . '&iso_country=' . $iso_country . '&iso_lang=' . $iso_lang . '&shop=' . urlencode($shop); $contents = Tools::file_get_contents($url, false, $stream_context); $check_info_offset = 3600; if ($contents !== false) { $content = explode('|', $contents); if (is_numeric($content[0])) { if (!$this->infoIgnore(false, $content[0])) { if (Validate::isCleanHtml($content[1])) { $this->putInfo($contents); $check_info_offset = 86400; } } } else { if ($content[0] == 'hide') { Configuration::deleteByName('PP_INFO_CONTENT'); } } } Configuration::updateValue('PP_INFO_CHECK_TIME', time() + $check_info_offset); } $content = $this->getInfo(); if ($content !== false) { if (!$this->infoIgnore($content)) { if (Validate::isCleanHtml($content[1])) { $result['status'] = 'success'; $result['content'] = $content[1]; } } } $this->content = Tools::jsonEncode($result); }
public function downloadExtraModule($name, $version, $force = false) { $extra_modules_dir = psmPPsetupExtraModulesDir(); if ($force || !is_dir($extra_modules_dir . '/' . $name . '/all') && !is_dir($extra_modules_dir . '/' . $name . '/' . $version)) { $status = 'error'; $post_data = http_build_query(array('key' => $this->module->name, 'ver' => $this->module->version, 'psm' => PSM::getPSMId($this->module), 'module' => $name, 'version' => $version)); $protocols = array('https', 'http'); $end_point = 'store.psandmore.com/query/integration.php'; $stream_context = stream_context_create(array('http' => array('method' => 'POST', 'content' => $post_data, 'header' => 'Content-type: application/x-www-form-urlencoded', 'timeout' => 5))); foreach ($protocols as $protocol) { if ($content = Tools::file_get_contents($protocol . '://' . $end_point, false, $stream_context)) { break; } } if ($content) { if ($content == '_none_') { if ($version == 'all' || strpos('pproperties', $name) == 0) { $status = 'rerun'; } else { $status = 'no_updates'; } } else { $dir = $extra_modules_dir . '/' . $name . '/'; $zip_file = $dir . $version . '.zip'; Tools::deleteFile($zip_file); if (file_put_contents($zip_file, $content) !== false) { if (Tools::ZipExtract($zip_file, $dir)) { $status = 'downloaded'; } Tools::deleteFile($zip_file); // if ($version != 'all' && is_dir($dir.'all')) // rename($dir.'all', $dir.$version); } } } } else { $status = 'downloaded'; } return $status; }
/** Called in Back Office when user clicks "Configure" */ public function getContent() { if (Configuration::get('PS_DISABLE_NON_NATIVE_MODULE')) { return '<div class="module_error alert alert-danger">' . $this->l('Non PrestaShop modules disabled.') . '</div>'; } $this->active_languages = $this->context->controller->getLanguages(); $this->default_language_id = $this->context->controller->default_form_language; $setup = $this->setupInstance(); if (!(int) Tools::getValue('pp')) { $setup->checkIntegration(); } $tab = '0'; $output0 = $output1 = $output2 = $output3 = $output4 = ''; $templates = null; $properties = null; if (Tools::isSubmit('submitRestoreDefaults')) { $tab = '0'; $setup->insertData(true); } elseif (Tools::isSubmit('cancelSaveTemplate')) { $tab = '0'; } elseif (Tools::isSubmit('cancelSaveProperty')) { $tab = '1'; } elseif (Tools::isSubmit('submitSaveTemplate')) { $result = $this->saveTemplate(); if ($result['error'] == '') { $tab = '0'; } else { $templates = $result['templates']; $output4 = $this->displayError($result['error']); $tab = '4'; } } elseif (Tools::isSubmit('submitSaveProperty')) { $result = $this->saveProperty(); if ($result['error'] == '') { $tab = '1'; } else { $properties = $result['properties']; $output4 = $this->displayError($result['error']); $tab = '4'; } } elseif (Tools::isSubmit('submitConfigSettings')) { $tab = '2'; Configuration::updateValue('PP_MEASUREMENT_SYSTEM', (int) Tools::getValue('measurement_system', 1)); Configuration::updateValue('PP_MEASUREMENT_SYSTEM_FO', (int) Tools::getValue('measurement_system_fo', 0)); Configuration::updateValue('PP_POWEREDBY', (int) Tools::getValue('poweredby', 0)); Configuration::updateValue('PP_TEMPLATE_NAME_IN_CATALOG', (int) Tools::getValue('template_name_in_catalog', 1)); Configuration::updateValue('PP_SHOW_POSITIONS', (int) Tools::getValue('show_positions', 0)); $output2 = $this->displayConfirmation($this->l('Settings updated')); } elseif (Tools::isSubmit('submitSetup')) { $tab = '2'; $setup->runSetup(); } elseif (Tools::isSubmit('submitIntegration')) { $tab = '2'; $setup->runIntegrationTest(); } elseif (Tools::isSubmit('clickClearCache')) { $tab = '2'; PSM::clearCache(); } elseif (Tools::isSubmit('submitStatistics')) { $tab = '3'; } elseif (Tools::isSubmit('clickEditTemplate')) { $tab = '4'; } elseif (Tools::isSubmit('clickDeleteTemplate')) { $tab = '0'; $this->deleteTemplate(); } elseif (Tools::isSubmit('clickHiddenStatusTemplate')) { $tab = '0'; $this->changeHiddenStatus(); } elseif (Tools::isSubmit('clickEditProperty')) { $tab = '4'; } elseif (Tools::isSubmit('clickDeleteProperty')) { $tab = '1'; $this->deleteProperty(); } $html = ''; if (version_compare(_PS_VERSION_, $this->ps_versions_compliancy['min']) < 0 || version_compare(_PS_VERSION_, $this->ps_versions_compliancy['max']) > 0) { $html .= $this->displayError($this->l('This module is not fully compatible with the installed PrestaShop version.') . ' ' . $this->compatibilityText() . '<br>' . $this->l('Please upgrade to the newer version.') . '<br>'); } if (count($this->integration_test_result) != 0) { $html .= $this->displayError($this->l('Integration test failed.')); $tab = '2'; } $tabs = array(); $tabs[0] = array('type' => 'templates', 'name' => $this->l('Templates'), 'html' => $output0 . $this->getTemplatesTabHtml()); $tabs[1] = array('type' => 'properties', 'name' => $this->l('Properties'), 'html' => $output1 . $this->getPropertiesTabHtml()); $tabs[2] = array('type' => 'settings', 'name' => $this->l('Settings'), 'html' => $output2 . $this->getSettingsTabHtml(Tools::isSubmit('submitIntegration') || Tools::isSubmit('submitSetup'))); $tabs[3] = array('type' => 'statistics', 'name' => $this->l('Statistics'), 'html' => $output3 . $this->getStatisticsTabHtml(Tools::isSubmit('submitStatistics'))); if ($tab == 4 && (Tools::isSubmit('clickEditTemplate') || Tools::isSubmit('submitSaveTemplate'))) { $mode = Tools::getValue('mode'); if ($mode == 'add') { $title = $this->l('Add template'); } elseif ($mode == 'copy') { $title = $this->l('Add template'); } else { $mode = 'edit'; $title = $this->l('Edit template'); } $tabs[4] = array('type' => 'modifyTemplate', 'name' => $title, 'html' => $output4 . $this->getEditTemplateTabHtml($templates, $mode, $title)); } elseif ($tab == 4 && (Tools::isSubmit('clickEditProperty') || Tools::isSubmit('submitSaveProperty'))) { $mode = Tools::getValue('mode'); if ($mode == 'add') { $type = (int) Tools::getValue('type'); if ($type == self::PROPERTY_TYPE_GENERAL) { $title = $this->l('Add property attribute'); } elseif ($type == self::PROPERTY_TYPE_BUY_BLOCK_TEXT) { $title = $this->l('Add property text'); } else { $title = $this->l('Add property dimension'); } } else { $mode = 'edit'; $title = $this->l('Edit property'); } $tabs[4] = array('type' => 'modifyProperty', 'name' => $title, 'html' => $output4 . $this->getEditPropertyTabHtml($properties, $mode, $title)); } //$helper->fields_value['tab'] = $tab; $helper = $this->createTemplate('pproperties'); $helper->tpl_vars['html'] = $html; $helper->tpl_vars['tabs'] = $tabs; $helper->tpl_vars['active'] = $tab; $helper->tpl_vars['version'] = $this->version; $helper->tpl_vars['ppe_id'] = PSM::getPSMId($this); $helper->tpl_vars['_path'] = $this->getPathUri(); $helper->tpl_vars['s_user_guide'] = $this->l('user guide'); $helper->tpl_vars['s_version'] = $this->l('Version'); $helper->tpl_vars['s_pp_info_ignore'] = $this->l("don't show this message again"); $helper->tpl_vars['token_adminpproperties'] = Tools::getAdminTokenLite('AdminPproperties'); $helper->tpl_vars['jstranslations'] = PP::safeOutputJS(array('rerun' => $this->l('Re-run Setup'), 'integration_module_success_IntegrationModuleIgnore' => $this->l('ignored - please re-run setup'), 'integration_module_success_IntegrationModuleIntegrate' => $this->l('integation activated - please re-run setup'), 'integration_module_rerun_IntegrationModuleCheckForUpdates' => $this->l('please re-run setup'), 'integration_module_downloaded_IntegrationModuleCheckForUpdates' => $this->l('update downloaded - please re-run setup'), 'integration_module_no_updates_IntegrationModuleCheckForUpdates' => $this->l('no updates available - please contact customer support'), 'integration_module_error' => $this->l('error occurred'))); if (!Module::isInstalled('psmextmanager') && Module::getInstanceByName('psmextmanager')) { $helper->tpl_vars['psmextmanager_install'] = $this->context->link->getAdminLink('AdminModules') . '&install=psmextmanager&tab_module=administration&module_name=psmextmanager&anchor=Psmextmanager'; } return $helper->generate(); }