public function getFields() { parent::validateFields(); if (isset($this->id)) { $fields['id_customer'] = intval($this->id); } $fields['secure_key'] = pSQL($this->secure_key); $fields['id_gender'] = intval($this->id_gender); $fields['lastname'] = pSQL(Tools::strtoupper($this->lastname)); $fields['firstname'] = pSQL($this->firstname); $fields['birthday'] = pSQL($this->birthday); $fields['email'] = pSQL($this->email); $fields['dni'] = pSQL($this->dni); $fields['newsletter'] = intval($this->newsletter); $fields['newsletter_date_add'] = pSQL($this->newsletter_date_add); $fields['ip_registration_newsletter'] = pSQL($this->ip_registration_newsletter); $fields['optin'] = intval($this->optin); $fields['passwd'] = pSQL($this->passwd); $fields['last_passwd_gen'] = pSQL($this->last_passwd_gen); $fields['active'] = intval($this->active); $fields['date_add'] = pSQL($this->date_add); $fields['date_upd'] = pSQL($this->date_upd); $fields['deleted'] = intval($this->deleted); return $fields; }
public function getData() { $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $this->query = 'SELECT SQL_CALC_FOUND_ROWS cr.code, ocr.name, COUNT(ocr.id_cart_rule) as total, ROUND(SUM(o.total_paid_real) / o.conversion_rate,2) as ca FROM ' . _DB_PREFIX_ . 'order_cart_rule ocr LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON o.id_order = ocr.id_order LEFT JOIN ' . _DB_PREFIX_ . 'cart_rule cr ON cr.id_cart_rule = ocr.id_cart_rule WHERE o.valid = 1 ' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . ' AND o.invoice_date BETWEEN ' . $this->getDate() . ' GROUP BY ocr.id_cart_rule'; if (Validate::IsName($this->_sort)) { $this->query .= ' ORDER BY `' . bqSQL($this->_sort) . '`'; if (isset($this->_direction) && (Tools::strtoupper($this->_direction) == 'ASC' || Tools::strtoupper($this->_direction) == 'DESC')) { $this->query .= ' ' . pSQL($this->_direction); } } if (($this->_start === 0 || Validate::IsUnsignedInt($this->_start)) && Validate::IsUnsignedInt($this->_limit)) { $this->query .= ' LIMIT ' . (int) $this->_start . ', ' . (int) $this->_limit; } $values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query); foreach ($values as &$value) { $value['ca'] = Tools::displayPrice($value['ca'], $currency); } $this->_values = $values; $this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()'); }
public static function executeCronTask() { $ts_module = new TrustedShops(); $ts_common = new TSCommon(); $common_count = 0; if (is_array(TSCommon::$available_languages)) { $to_remove = array(); foreach (array_keys(TSCommon::$available_languages) as $iso) { $alerts_infos = RatingAlert::getAlertsInformations($iso); ///print_r($alerts_infos); if ($alerts_infos != false) { $common_count += count($alerts_infos); foreach ($alerts_infos as $infos) { $cert = Configuration::get(TSCommon::PREFIX_TABLE . 'CERTIFICATE_' . Tools::strtoupper($infos['iso'])); $certificate = (array) Tools::jsonDecode(Tools::htmlentitiesDecodeUTF8($cert)); $subject = $ts_module->l('title_part_1') . ' ' . Configuration::get('PS_SHOP_NAME') . $ts_module->l('title_part_2'); $template_vars = array('{ts_id}' => $certificate['tsID'], '{button_url}' => TSCommon::getHttpHost(true, true) . _MODULE_DIR_ . $ts_module->name . '/views/img', '{rating_url}' => $ts_common->getRatingUrlWithBuyerEmail($infos['id_lang'], $infos['id_order'], $infos['email'])); $result = Mail::Send((int) $infos['id_lang'], self::MAIL_TEMPLATE, $subject, $template_vars, $infos['email'], null, Configuration::get('PS_SHOP_EMAIL'), Configuration::get('PS_SHOP_NAME'), null, null, dirname(__FILE__) . '/../mails/'); if ($result) { $to_remove[] = (int) $infos['id_alert']; } } } } if (count($to_remove) > 0) { self::removeAlerts($to_remove); } } return count($to_remove) == $common_count; }
public static function ignoreRow($row) { if (count($row) == 1 && empty($row[0])) { return true; } return isset($row['id']) && is_string($row['id']) && Tools::strtoupper($row['id']) == 'ID' || isset($row['id_product']) && is_string($row['id_product']) && Tools::strtoupper($row['id_product']) == 'PRODUCT ID*'; }
private function curlConnection($method, $url, $timeout, $charset, array $data = null) { if (Tools::strtoupper($method) === 'POST') { $postFields = $data ? http_build_query($data, '', '&') : ""; $contentLength = "Content-length: " . Tools::strlen($postFields); $methodOptions = array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postFields); } else { $contentLength = null; $methodOptions = array(CURLOPT_HTTPGET => true); } $options = array(CURLOPT_HTTPHEADER => array("Content-Type: application/x-www-form-urlencoded; charset=" . $charset, $contentLength, 'lib-description: php:' . PagSeguroLibrary::getVersion(), 'language-engine-description: php:' . PagSeguroLibrary::getPHPVersion()), CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CONNECTTIMEOUT => $timeout); if (!is_null(PagSeguroLibrary::getModuleVersion())) { array_push($options[CURLOPT_HTTPHEADER], 'module-description: ' . PagSeguroLibrary::getModuleVersion()); } if (!is_null(PagSeguroLibrary::getCMSVersion())) { array_push($options[CURLOPT_HTTPHEADER], 'cms-description: ' . PagSeguroLibrary::getCMSVersion()); } $options = $options + $methodOptions; $curl = curl_init(); curl_setopt_array($curl, $options); $resp = curl_exec($curl); $info = curl_getinfo($curl); $error = curl_errno($curl); $errorMessage = curl_error($curl); curl_close($curl); $this->setStatus((int) $info['http_code']); $this->setResponse((string) $resp); if ($error) { throw new Exception("CURL can't connect: {$errorMessage}"); } else { return true; } }
function hookHeader($params) { global $smarty, $cookie; $id_category = intval(Tools::getValue('id_category')); if (!$id_category) { if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) { if (isset($regs[2]) and is_numeric($regs[2])) { $id_category = intval($regs[2]); } elseif (isset($regs[5]) and is_numeric($regs[5])) { $id_category = intval($regs[5]); } } elseif ($id_product = intval(Tools::getValue('id_product'))) { $product = new Product($id_product); $id_category = $product->id_category_default; } } $category = new Category($id_category); $orderByValues = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity'); $orderWayValues = array(0 => 'ASC', 1 => 'DESC'); $orderBy = Tools::strtolower(Tools::getValue('orderby', $orderByValues[intval(Configuration::get('PS_PRODUCTS_ORDER_BY'))])); $orderWay = Tools::strtoupper(Tools::getValue('orderway', $orderWayValues[intval(Configuration::get('PS_PRODUCTS_ORDER_WAY'))])); if (!in_array($orderBy, $orderByValues)) { $orderBy = $orderByValues[0]; } if (!in_array($orderWay, $orderWayValues)) { $orderWay = $orderWayValues[0]; } $smarty->assign(array('feedUrl' => 'http://' . Tools::getHttpHost(false, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/rss.php?id_category=' . $id_category . '&orderby=' . $orderBy . '&orderway=' . $orderWay)); return $this->display(__FILE__, 'feederHeader.tpl'); }
public function postProcess() { global $currentIndex; if (isset($_POST['submitDatabase' . $this->table])) { if ($this->tabAccess['edit'] === '1') { foreach ($this->_fieldsDatabase as $field => $values) { if (isset($values['required']) and $values['required']) { if (($value = Tools::getValue($field)) == false and (string) $value != '0') { $this->_errors[] = Tools::displayError('field') . ' <b>' . $values['title'] . '</b> ' . Tools::displayError('is required'); } } } if (!sizeof($this->_errors)) { /* Datas are not saved in database but in config/settings.inc.php */ $settings = array(); foreach ($_POST as $k => $value) { if ($value) { $settings['_' . Tools::strtoupper($k) . '_'] = $value; } } rewriteSettingsFile(NULL, NULL, $settings); Tools::redirectAdmin($currentIndex . '&conf=6' . '&token=' . $this->token); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.'); } } }
public static function getItemDescriptionByKey($itemKey) { $itemKey = Tools::strtoupper($itemKey); if (isset(self::$availableItemKeysList[$itemKey])) { return self::$availableItemKeysList[$itemKey]; } else { return false; } }
public static function getDocumentByType($documentType) { $documentType = Tools::strtoupper($documentType); if (isset(self::$availableDocumentList[$documentType])) { return self::$availableDocumentList[$documentType]; } else { return false; } }
protected function setCurrencyIso() { $this->currency_iso = Tools::strtoupper(Db::getInstance()->getValue(' SELECT `iso_code` FROM `' . _DB_PREFIX_ . 'currency` WHERE `id_currency` = ' . (int) $this->id_currency)); }
/** * Make a request to the Syspay API * @param Syspay_Merchant_Request $request The request to send to the API * @return mixed The response to the request * @throws Syspay_Merchant_RequestException If the request could not be processed by the API */ public function request(Syspay_Merchant_Request $request) { $this->body = $this->headers = $this->data = null; $headers = array('Accept: application/json', 'X-Wsse: ' . $this->generateAuthHeader($this->username, $this->secret)); $url = rtrim($this->baseUrl, '/') . '/' . ltrim($request->getPath(), '/'); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // TODO: verify ssl and provide certificate in package curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $method = Tools::strtoupper($request->getMethod()); // Per-method special handling switch ($method) { case 'PUT': case 'POST': $body = Tools::jsonEncode($request->getData()); array_push($headers, 'Content-Type: application/json'); array_push($headers, 'Content-Length: ' . Tools::strlen($body)); curl_setopt($ch, CURLOPT_POSTFIELDS, $body); break; case 'GET': $queryParams = $request->getData(); if (is_array($queryParams)) { $url .= '?' . http_build_query($queryParams); } break; case 'DELETE': break; default: throw new Exception('Unsupported method given: ' . $method); } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); if ($response === false) { throw new Exception(curl_error($ch), curl_errno($ch)); } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); list($headers, $body) = explode("\r\n\r\n", $response, 2); $this->headers = $headers; $this->body = $body; if (!in_array($httpCode, array(200, 201))) { throw new Syspay_Merchant_RequestException($httpCode, $headers, $body); } $decoded = Tools::jsonDecode($body); if ($decoded instanceof stdClass && isset($decoded->data) && $decoded->data instanceof stdClass) { $this->data = $decoded->data; return $request->buildResponse($decoded->data); } else { throw new Syspay_Merchant_UnexpectedResponseException('Unable to decode response from json', $body); } return false; }
public function postProcess() { global $currentIndex; if (isset($_POST['submitDatabase' . $this->table])) { if ($this->tabAccess['edit'] === '1') { foreach ($this->_fieldsDatabase as $field => $values) { if (isset($values['required']) and $values['required']) { if (($value = Tools::getValue($field)) == false and (string) $value != '0') { $this->_errors[] = Tools::displayError('field') . ' <b>' . $values['title'] . '</b> ' . Tools::displayError('is required.'); } } } if (!sizeof($this->_errors)) { /* Datas are not saved in database but in config/settings.inc.php */ $settings = array(); foreach ($_POST as $k => $value) { if ($value) { $settings['_' . Tools::strtoupper($k) . '_'] = $value; } } rewriteSettingsFile(NULL, NULL, $settings); Tools::redirectAdmin($currentIndex . '&conf=6' . '&token=' . $this->token); } } else { $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } if (Tools::isSubmit('submitEngine')) { if (!isset($_POST['tablesBox']) or !sizeof($_POST['tablesBox'])) { $this->_errors[] = Tools::displayError('You did not select any tables'); } else { $available_engines = $this->_getEngines(); $tables_status = $this->_getTablesStatus(); $tables_engine = array(); foreach ($tables_status as $table) { $tables_engine[$table['Name']] = $table['Engine']; } $engineType = pSQL(Tools::getValue('engineType')); /* Datas are not saved in database but in config/settings.inc.php */ $settings = array('_MYSQL_ENGINE_' => $engineType); rewriteSettingsFile(NULL, NULL, $settings); foreach ($_POST['tablesBox'] as $table) { if ($engineType == $tables_engine[$table]) { $this->_errors[] = $table . ' ' . $this->l('is already in') . ' ' . $engineType; } else { if (!Db::getInstance()->Execute('ALTER TABLE `' . bqSQL($table) . '` ENGINE=`' . bqSQL($engineType) . '`')) { $this->_errors[] = $this->l('Can\'t change engine for') . ' ' . $table; } else { echo '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->l('Confirmation') . '" />' . $this->l('Engine change of') . ' ' . $table . ' ' . $this->l('to') . ' ' . $engineType . '</div>'; } } } } } }
public function addCurrency($id, $rate = 'CBRF', $plus = 0) { $rate = Tools::strtoupper($rate); $plus = str_replace(',', '.', $plus); if ($rate == 'CBRF' && $plus > 0) { $this->currencies[] = array('id' => $this->prepareField(Tools::strtoupper($id)), 'rate' => 'CBRF', 'plus' => (double) $plus); } else { $rate = str_replace(',', '.', $rate); $this->currencies[] = array('id' => $this->prepareField(Tools::strtoupper($id)), 'rate' => (double) $rate); } return true; }
public function renderForm($data) { $helper = $this->getFormHelper(); $fields = array(); foreach (self::$networks as $network) { $fields[] = array('type' => 'switch', 'label' => $network, 'name' => 'PS_SC_' . Tools::strtoupper($network), 'values' => array(array('id' => Tools::strtolower($network) . '_active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => Tools::strtolower($network) . '_active_off', 'value' => 0, 'label' => $this->l('Disabled')))); } $this->fields_form[1]['form'] = array('legend' => array('title' => $this->l('Widget Separator Form.')), 'input' => $fields, 'submit' => array('title' => $this->l('Save'), 'class' => 'button')); $default_lang = (int) Configuration::get('PS_LANG_DEFAULT'); $helper->tpl_vars = array('fields_value' => $this->getConfigFieldsValues($data), 'languages' => Context::getContext()->controller->getLanguages(), 'id_language' => $default_lang); return $helper->generateForm($this->fields_form); }
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 renderForm($args, $data) { $helper = $this->getFormHelper(); $align = array(array('id' => 'separator_align_center', 'name' => $this->l('Align center')), array('id' => 'separator_align_left', 'name' => $this->l('Align left')), array('id' => 'separator_align_right', 'name' => $this->l('Align right'))); $fields = array(); foreach (self::$networks as $network) { $fields[] = array('type' => 'switch', 'label' => $network, 'name' => 'PS_SC_' . Tools::strtoupper($network), 'values' => array(array('id' => Tools::strtolower($network) . '_active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => Tools::strtolower($network) . '_active_off', 'value' => 0, 'label' => $this->l('Disabled')))); } $this->fields_form[1]['form'] = array('legend' => array('title' => $this->l('Widget Separator Form.')), 'input' => $fields, 'submit' => array('title' => $this->l('Save'), 'class' => 'button')); $default_lang = (int) $this->config->get('config_language_id'); $helper->tpl_vars = array('fields_value' => $this->getConfigFieldsValues($data), 'id_language' => $default_lang); return $helper->generateForm($this->fields_form); }
public function getFields() { parent::validateFields(); $fields['id_profile'] = intval($this->id_profile); $fields['lastname'] = pSQL(Tools::strtoupper($this->lastname)); $fields['firstname'] = pSQL(Tools::ucfirst($this->firstname)); $fields['email'] = pSQL($this->email); $fields['passwd'] = pSQL($this->passwd); $fields['last_passwd_gen'] = pSQL($this->last_passwd_gen); $fields['stats_date_from'] = pSQL($this->stats_date_from); $fields['stats_date_to'] = pSQL($this->stats_date_to); $fields['active'] = intval($this->active); return $fields; }
private function getCipher() { if ($this->cipher !== false) { return $this->cipher; } $available = mcrypt_list_algorithms(); foreach ($this->ciphers as $cipher) { if (in_array($cipher, $available)) { $this->cipher = $cipher; return constant('MCRYPT_' . Tools::strtoupper(str_replace('-', '_', $cipher))); } } $this->addError('no available cipher'); return false; }
public function setMonths($year) { $months = array(); for ($i = '01'; $i <= 12; $i = sprintf('%02d', $i + 1)) { $months[$i . '_' . $year] = array('label' => Dashgoals::$month_labels[$i], 'values' => array()); } foreach (Dashgoals::$types as $type) { foreach ($months as $month => &$month_row) { $key = 'dashgoals_' . $type . '_' . $month; if (Tools::isSubmit('submitDashGoals')) { ConfigurationKPI::updateValue(Tools::strtoupper($key), (double) Tools::getValue($key)); } $month_row['values'][$type] = ConfigurationKPI::get(Tools::strtoupper($key)); } } return $months; }
public function postProcess() { if (Tools::isSubmit('sendCampaign')) { $yes = (string) Tools::getValue('YES', ''); $yes = Tools::strtoupper($yes); if ($yes == Tools::strtoupper(Translate::getModuleTranslation('expressmailing', 'YES', 'footer_validation'))) { if ($this->sendCampaignAPI()) { $this->confirmations[] = $this->module->l('Your campaign is now sending ...', 'adminmarketingestep8'); // Tracking Prestashop // ------------------- return Db::getInstance()->update('expressmailing_email', array('campaign_state' => '1', 'campaign_api_validation' => '1'), 'campaign_id = ' . $this->campaign_id); } } else { $this->errors[] = sprintf($this->module->l('Please fill the %s field', 'adminmarketingestep8'), '« ' . Translate::getModuleTranslation('expressmailing', 'YES', 'footer_validation') . ' »'); } return false; } }
public function postProcess() { parent::postProcess(); $type = Tools::getValue('type'); $func = Tools::getValue('func'); $arr = array($type, $func); $arr = array_merge($arr, $_REQUEST); $dd = serialize($arr); $this->module->logSave('pokupki ' . $dd); $key = Tools::getValue('auth-token'); $sign = Configuration::get('YA_POKUPKI_TOKEN'); if (Tools::strtoupper($sign) != Tools::strtoupper($key)) { header('HTTP/1.1 403 Forbidden'); header('Status: 403 Forbidden'); echo '<h1>Wrong token</h1>'; exit; } else { $json = Tools::file_get_contents("php://input"); $this->module->logSave('pokupki' . $json); if (!$json) { header('HTTP/1.1 403 Forbidden'); header('Status: 403 Forbidden'); echo '<h1>No data posted</h1>'; exit; } else { header('Content-type:application/json; charset=utf-8'); $partner = new Partner(); $data = Tools::jsonDecode($json); if ($type == 'cart') { $partner->requestItems($data); } elseif ($type == 'order') { if ($func == 'accept') { $partner->orderAccept($data); } elseif ($func == 'status') { $partner->alertOrderStatus($data); } } else { header('HTTP/1.0 404 Not Found'); echo '<h1>Wrong controller</h1>'; exit; } } } }
private function createNewServiceAccount() { $api_key = Tools::strtoupper(md5(time())); $resources = WebserviceRequest::getResources(); $db_instance = Db::getInstance(); $db_instance->insert('webservice_account', array('key' => $api_key, 'active' => '1')); $account_id = $db_instance->Insert_ID(); $shop_id = (int) Context::getContext()->shop->id; $db_instance->insert('webservice_account_shop', array('id_webservice_account' => $account_id, 'id_shop' => $shop_id)); $values = array(array('resource' => 'customers', 'method' => 'PUT', 'id_webservice_account' => $account_id)); foreach (array_keys($resources) as $resource) { $values[] = array('resource' => $resource, 'method' => 'GET', 'id_webservice_account' => $account_id); } $db_instance->insert('webservice_permission', $values); Configuration::updateValue('NEWSLETTER2GO_API_KEY', $api_key); Configuration::updateValue('NEWSLETTER2GO_API_ACCOUNT', $account_id); Configuration::updateValue('PS_WEBSERVICE', 1); return $api_key; }
/** * Make a $method request * @param string $method - GET/POST/... * @param string $url - the URL * @param array|string|null $params - if it's a string, it will passed as it is; if it's an array, http_build_query will be used to convert it to a string * @param int $timeout - request timeout in seconds * @return string - the response content (without headers) */ public function request($method, $url, $params, $timeout = 30) { $options = array(CURLOPT_HTTPGET => false, CURLOPT_HEADER => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => false, CURLOPT_MAXREDIRS => 0, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_USERAGENT => 'curl', CURLOPT_CONNECTTIMEOUT => $timeout, CURLOPT_TIMEOUT => $timeout); switch (Tools::strtoupper($method)) { case 'GET': if (!empty($params)) { $url .= '?' . (is_array($params) ? http_build_query($params) : (string) $params); } $ch = curl_init($url); $options[CURLOPT_HTTPGET] = true; break; default: // post... $ch = curl_init($url); $options[CURLOPT_CUSTOMREQUEST] = $method; if (!empty($params)) { $options[CURLOPT_POSTFIELDS] = is_array($params) ? http_build_query($params) : (string) $params; $this->additionalHeaders['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8'; } break; } $headers = array(); if (!empty($this->additionalHeaders)) { foreach ($this->additionalHeaders as $key => $value) { $headers[] = $key . ': ' . $value; } $options[CURLOPT_HTTPHEADER] = $headers; } foreach ($options as $optKey => $optVal) { curl_setopt($ch, $optKey, $optVal); } $response = curl_exec($ch); $curlInfo = curl_getinfo($ch); $errCode = curl_errno($ch); $errMsg = curl_error($ch); curl_close($ch); PilipayLogger::instance()->log('debug', "CURL: " . print_r(array('request' => array('method' => $method, 'url' => $url, 'params' => $params, 'headers' => $headers), 'response' => array('errno' => $errCode, 'error' => $errMsg, 'content' => $response)), true)); $headerSize = $curlInfo['header_size']; $this->responseHeaders = self::parseResponseHeader(Tools::substr($response, 0, $headerSize)); $this->responseHeaders['redirect_url'] = $curlInfo['redirect_url']; $this->responseContent = Tools::substr($response, $headerSize); return $this->responseContent; }
public function getData() { $this->_query = ' SELECT SQL_CALC_FOUND_ROWS od.name, COUNT(od.id_discount) as total, SUM(o.total_paid_real) / o.conversion_rate as ca FROM ' . _DB_PREFIX_ . 'order_discount od LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON o.id_order = od.id_order WHERE o.valid = 1 AND o.invoice_date BETWEEN ' . $this->getDate() . ' GROUP BY od.id_discount'; if (Validate::IsName($this->_sort)) { $this->_query .= ' ORDER BY `' . $this->_sort . '`'; if (isset($this->_direction) && (Tools::strtoupper($this->_direction) == 'ASC' || Tools::strtoupper($this->_direction) == 'DESC')) { $this->_query .= ' ' . pSQL($this->_direction); } } if (($this->_start === 0 or Validate::IsUnsignedInt($this->_start)) and Validate::IsUnsignedInt($this->_limit)) { $this->_query .= ' LIMIT ' . $this->_start . ', ' . $this->_limit; } $this->_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($this->_query); $this->_totalCount = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS() AS `' . md5($this->_query) . '`'); }
public function verifCity($postal, $city) { $soapclient = $this->getSoapClient(); $soapclient->__setSOAPHeaders(array($this->_header)); $cities = $soapclient->citiesGuide(array('zipCode' => $postal)); if (!isset($cities->City)) { return false; } if (is_array($cities->City)) { foreach ($cities->City as $v) { if (Tools::strtoupper($v->name) == Tools::strtoupper($city)) { return true; } } } else { if (Tools::strtoupper($city) == Tools::strtoupper($cities->City->name)) { return true; } } return false; }
public function getContent() { $output = ''; if (Tools::isSubmit('submitSocialSharing')) { foreach (self::$networks as $network) { Configuration::updateValue('PS_SC_' . Tools::strtoupper($network), (int) Tools::getValue('PS_SC_' . Tools::strtoupper($network))); } $this->_clearCache($this->templateFile); $output .= $this->displayConfirmation($this->getTranslator()->trans('Settings updated.', array(), 'Admin.Notifications.Success')); Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=6&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name); } $helper = new HelperForm(); $helper->submit_action = 'submitSocialSharing'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array('fields_value' => $this->getConfigFieldsValues()); $fields = array(); foreach (self::$networks as $network) { $fields[] = array('type' => 'switch', 'label' => $network, 'name' => 'PS_SC_' . Tools::strtoupper($network), 'values' => array(array('id' => Tools::strtolower($network) . '_active_on', 'value' => 1, 'label' => $this->getTranslator()->trans('Enabled', array(), 'Admin.Global')), array('id' => Tools::strtolower($network) . '_active_off', 'value' => 0, 'label' => $this->getTranslator()->trans('Disabled', array(), 'Admin.Global')))); } return $output . $helper->generateForm(array(array('form' => array('legend' => array('title' => $this->displayName, 'icon' => 'icon-share'), 'input' => $fields, 'submit' => array('title' => $this->getTranslator()->trans('Save', array(), 'Admin.Actions')))))); }
/** * Do CURL request with authorization */ private function doRequest($resource, $method, $input) { $called_url = $this->base_url . "/" . $resource; $ch = curl_init($called_url); $auth_header = 'api-key:' . $this->api_key; $content_header = "Content-Type:application/json"; if (Tools::strtoupper(Tools::substr(PHP_OS, 0, 3)) === 'WIN') { // Windows only over-ride curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); } curl_setopt($ch, CURLOPT_HTTPHEADER, array($auth_header, $content_header)); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $input); $data = curl_exec($ch); if (curl_errno($ch)) { echo '<div style="background:#d14836; padding:10px; color:#fff; font-weight:600; position:aboslute;width:100%;top:0;">Curl error: ' . curl_error($ch) . '</div>'; } curl_close($ch); return Tools::jsonDecode($data, true); }
/** * Get the current objects' list form the database * * @param integer $id_lang Language used for display * @param string $orderBy ORDER BY clause * @param string $_orderWay Order way (ASC, DESC) * @param integer $start Offset in LIMIT clause * @param integer $limit Row count in LIMIT clause */ public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL) { global $cookie; /* Manage default params values */ if (empty($limit)) { $limit = !isset($cookie->{$this->table . '_pagination'}) ? $this->_pagination[1] : ($limit = $cookie->{$this->table . '_pagination'}); } if (!Validate::isTableOrIdentifier($this->table)) { die(Tools::displayError('Table name is invalid:') . ' "' . $this->table . '"'); } if (empty($orderBy)) { $orderBy = $cookie->__get($this->table . 'Orderby') ? $cookie->__get($this->table . 'Orderby') : $this->_defaultOrderBy; } if (empty($orderWay)) { $orderWay = $cookie->__get($this->table . 'Orderway') ? $cookie->__get($this->table . 'Orderway') : 'ASC'; } $limit = (int) Tools::getValue('pagination', $limit); $cookie->{$this->table . '_pagination'} = $limit; /* Check params validity */ if (!Validate::isOrderBy($orderBy) or !Validate::isOrderWay($orderWay) or !is_numeric($start) or !is_numeric($limit) or !Validate::isUnsignedId($id_lang)) { die(Tools::displayError('get list params is not valid')); } /* Determine offset from current page */ if ((isset($_POST['submitFilter' . $this->table]) or isset($_POST['submitFilter' . $this->table . '_x']) or isset($_POST['submitFilter' . $this->table . '_y'])) and !empty($_POST['submitFilter' . $this->table]) and is_numeric($_POST['submitFilter' . $this->table])) { $start = (int) ($_POST['submitFilter' . $this->table] - 1) * $limit; } /* Cache */ $this->_lang = (int) $id_lang; $this->_orderBy = $orderBy; $this->_orderWay = Tools::strtoupper($orderWay); /* SQL table : orders, but class name is Order */ $sqlTable = $this->table == 'order' ? 'orders' : $this->table; /* Query in order to get results with all fields */ $sql = 'SELECT SQL_CALC_FOUND_ROWS ' . ($this->_tmpTableFilter ? ' * FROM (SELECT ' : '') . ' ' . ($this->lang ? 'b.*, ' : '') . 'a.*' . (isset($this->_select) ? ', ' . $this->_select . ' ' : '') . ' FROM `' . _DB_PREFIX_ . $sqlTable . '` a ' . ($this->lang ? 'LEFT JOIN `' . _DB_PREFIX_ . $this->table . '_lang` b ON (b.`' . $this->identifier . '` = a.`' . $this->identifier . '` AND b.`id_lang` = ' . (int) $id_lang . ')' : '') . ' ' . (isset($this->_join) ? $this->_join . ' ' : '') . ' WHERE 1 ' . (isset($this->_where) ? $this->_where . ' ' : '') . ($this->deleted ? 'AND a.`deleted` = 0 ' : '') . (isset($this->_filter) ? $this->_filter : '') . ' ' . (isset($this->_group) ? $this->_group . ' ' : '') . ' ' . (isset($this->_filterHaving) || isset($this->_having) ? 'HAVING ' : '') . (isset($this->_filterHaving) ? ltrim($this->_filterHaving, ' AND ') : '') . (isset($this->_having) ? $this->_having . ' ' : '') . ' ORDER BY ' . ($orderBy == $this->identifier ? 'a.' : '') . '`' . pSQL($orderBy) . '` ' . pSQL($orderWay) . ($this->_tmpTableFilter ? ') tmpTable WHERE 1' . $this->_tmpTableFilter : '') . ' LIMIT ' . (int) $start . ',' . (int) $limit; $this->_list = Db::getInstance()->ExecuteS($sql); $this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `' . _DB_PREFIX_ . $this->table . '`'); }
public static function getPSMId($module) { $key = 'PSM_ID_' . Tools::strtoupper($module->name); if (!isset(self::$s_cache[$key])) { self::$s_cache[$key] = Configuration::getGlobalValue($key); if (self::$s_cache[$key] === false) { self::$s_cache[$key] = ''; for ($i = 0; $i < 3; $i++) { self::$s_cache[$key] .= Tools::passwdGen(4, 'NUMERIC') . '-'; } self::$s_cache[$key] .= Tools::passwdGen(4, 'NUMERIC'); Configuration::updateGlobalValue($key, self::$s_cache[$key]); } } return self::$s_cache[$key]; }
public function hookDisplayFooter() { $html = ''; if ((int) Configuration::get('PS_TC_ACTIVE') == 1 && Tools::getValue('live_configurator_token') && Tools::getValue('live_configurator_token') == $this->getLiveConfiguratorToken() && Tools::getIsset('id_employee') && $this->checkEnvironment()) { if (Tools::isSubmit('submitLiveConfigurator')) { Configuration::updateValue('PS_TC_THEME', Tools::getValue('theme')); Configuration::updateValue('PS_TC_FONT', Tools::getValue('theme_font')); } $ad_image = $this->_path . 'img/' . $this->context->language->iso_code . '/advertisement.png'; if (!file_exists($ad_image)) { $ad_image = $this->_path . 'img/en/advertisement.png'; } $this->smarty->assign(array('themes' => Tools::unserialize(Configuration::get('PS_TC_THEMES')), 'fonts' => Tools::unserialize(Configuration::get('PS_TC_FONTS')), 'theme_font' => Tools::getValue('theme_font', Configuration::get('PS_TC_FONT')), 'live_configurator_token' => $this->getLiveConfiguratorToken(), 'id_shop' => (int) $this->context->shop->id, 'id_employee' => is_object($this->context->employee) ? (int) $this->context->employee->id : Tools::getValue('id_employee'), 'advertisement_image' => $ad_image, 'advertisement_url' => 'http://addons.prestashop.com/en/205-premium-templates?utm_source=back-office' . '&utm_medium=theme-configurator' . '&utm_campaign=back-office-' . Tools::strtoupper($this->context->language->iso_code) . '&utm_content=' . (defined('_PS_HOST_MODE_') ? 'ondemand' : 'download'), 'advertisement_text' => $this->l('Over 800 PrestaShop premium templates! Browse now!'))); $html .= $this->display(__FILE__, 'live_configurator.tpl'); } $this->context->smarty->assign(array('htmlitems' => $this->getItemsFromHook('footer'), 'hook' => 'footer')); return $html . $this->display(__FILE__, 'hook.tpl'); }