From e33355b2d722abe3cd31c076c33e3afbf3b9776d Mon Sep 17 00:00:00 2001 From: condor2 Date: Tue, 21 Jul 2020 00:16:57 +0300 Subject: [PATCH] Added more fixes from Github --- .../controller/extension/module/carousel.php | 4 - .../extension/payment/bank_transfer.php | 2 +- upload/admin/controller/marketing/coupon.php | 2 +- upload/admin/controller/sale/order.php | 8 +- upload/admin/controller/sale/voucher.php | 21 +- upload/admin/controller/setting/setting.php | 25 +++ upload/admin/controller/startup/startup.php | 8 + upload/admin/language/en-gb/mail/voucher.php | 3 +- upload/admin/language/en-gb/sale/voucher.php | 1 - .../admin/language/en-gb/setting/setting.php | 1 + upload/admin/model/catalog/product.php | 2 +- upload/admin/model/customer/customer.php | 2 +- upload/admin/model/localisation/tax_class.php | 2 +- upload/admin/model/tool/backup.php | 68 ++---- upload/admin/model/user/api.php | 2 +- upload/admin/view/template/common/header.twig | 12 +- .../admin/view/template/common/security.twig | 2 - .../view/template/customer/customer_form.twig | 2 +- .../view/template/customer/customer_ip.twig | 4 +- .../admin/view/template/sale/order_form.twig | 2 +- .../admin/view/template/setting/setting.twig | 14 ++ upload/catalog/controller/account/voucher.php | 4 +- upload/catalog/controller/common/cart.php | 2 +- .../controller/extension/payment/eway.php | 2 +- upload/catalog/controller/startup/startup.php | 10 +- upload/install/controller/install/step_3.php | 80 ++++--- .../install/language/en-gb/install/step_3.php | 8 +- upload/install/opencart.sql | 9 +- .../install/view/template/install/step_3.twig | 85 ++++--- upload/system/config/admin.php | 4 +- upload/system/config/catalog.php | 2 +- upload/system/config/default.php | 2 +- upload/system/framework.php | 6 +- upload/system/library/cache/redis.php | 55 ++--- upload/system/library/mail/smtp.php | 207 +++++------------- upload/system/library/session/db.php | 63 +++--- 36 files changed, 333 insertions(+), 393 deletions(-) diff --git a/upload/admin/controller/extension/module/carousel.php b/upload/admin/controller/extension/module/carousel.php index 0d0c2440731..920f134c040 100644 --- a/upload/admin/controller/extension/module/carousel.php +++ b/upload/admin/controller/extension/module/carousel.php @@ -125,10 +125,6 @@ public function index() { $data['status'] = ''; } - $this->load->model('design/banner'); - - $data['banners'] = $this->model_design_banner->getBanners(); - $data['header'] = $this->load->controller('common/header'); $data['column_left'] = $this->load->controller('common/column_left'); $data['footer'] = $this->load->controller('common/footer'); diff --git a/upload/admin/controller/extension/payment/bank_transfer.php b/upload/admin/controller/extension/payment/bank_transfer.php index 9bb48822ebb..afe12f7c8bc 100644 --- a/upload/admin/controller/extension/payment/bank_transfer.php +++ b/upload/admin/controller/extension/payment/bank_transfer.php @@ -52,7 +52,7 @@ public function index() { $this->load->model('localisation/language'); - $data['payment_bank_transfer'] = array(); + $data['payment_bank_transfer_bank'] = array(); $languages = $this->model_localisation_language->getLanguages(); diff --git a/upload/admin/controller/marketing/coupon.php b/upload/admin/controller/marketing/coupon.php index d7494bfb7bc..edb1a446593 100644 --- a/upload/admin/controller/marketing/coupon.php +++ b/upload/admin/controller/marketing/coupon.php @@ -490,7 +490,7 @@ protected function validateForm() { $this->error['name'] = $this->language->get('error_name'); } - if ((utf8_strlen($this->request->post['code']) < 3) || (utf8_strlen($this->request->post['code']) > 10)) { + if ((utf8_strlen($this->request->post['code']) < 3) || (utf8_strlen($this->request->post['code']) > 20)) { $this->error['code'] = $this->language->get('error_code'); } diff --git a/upload/admin/controller/sale/order.php b/upload/admin/controller/sale/order.php index 402e8cc282f..f6b66392965 100644 --- a/upload/admin/controller/sale/order.php +++ b/upload/admin/controller/sale/order.php @@ -383,7 +383,7 @@ protected function getList() { $session->start(); - $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + $this->model_user_api->deleteApiSessionBySessionId($session->getId()); $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); @@ -690,7 +690,7 @@ public function getForm() { $session->start(); - $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + $this->model_user_api->deleteApiSessionBySessionId($session->getId()); $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); @@ -990,8 +990,6 @@ public function info() { $data['commission'] = $this->currency->format($order_info['commission'], $order_info['currency_code'], $order_info['currency_value']); - $this->load->model('customer/customer'); - $data['commission_total'] = $this->model_customer_customer->getTotalTransactionsByOrderId($this->request->get['order_id']); $this->load->model('localisation/order_status'); @@ -1233,7 +1231,7 @@ public function info() { $session->start(); - $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + $this->model_user_api->deleteApiSessionBySessionId($session->getId()); $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); diff --git a/upload/admin/controller/sale/voucher.php b/upload/admin/controller/sale/voucher.php index 047b954c05f..28130a6164b 100644 --- a/upload/admin/controller/sale/voucher.php +++ b/upload/admin/controller/sale/voucher.php @@ -177,7 +177,7 @@ protected function getList() { } else { $order_href = ''; } - + $data['vouchers'][] = array( 'voucher_id' => $result['voucher_id'], 'code' => $result['code'], @@ -567,6 +567,9 @@ public function send() { } if ($vouchers) { + $this->load->model('sale/order'); + $this->load->model('sale/voucher_theme'); + foreach ($vouchers as $voucher_id) { $voucher_info = $this->model_sale_voucher->getVoucher($voucher_id); @@ -577,8 +580,6 @@ public function send() { $order_id = 0; } - $this->load->model('sale/order'); - $order_info = $this->model_sale_order->getOrder($order_id); // If voucher belongs to an order @@ -598,8 +599,6 @@ public function send() { $data['text_redeem'] = sprintf($language->get('text_redeem'), $voucher_info['code']); $data['text_footer'] = $language->get('text_footer'); - $this->load->model('sale/voucher_theme'); - $voucher_theme_info = $this->model_sale_voucher_theme->getVoucherTheme($voucher_info['voucher_theme_id']); if ($voucher_theme_info && is_file(DIR_IMAGE . $voucher_theme_info['image'])) { @@ -628,25 +627,25 @@ public function send() { $mail->send(); // If voucher does not belong to an order - } else { + } else { + $this->language->load('mail/voucher'); + $data['title'] = sprintf($this->language->get('text_subject'), $voucher_info['from_name']); $data['text_greeting'] = sprintf($this->language->get('text_greeting'), $this->currency->format($voucher_info['amount'], $this->config->get('config_currency'))); $data['text_from'] = sprintf($this->language->get('text_from'), $voucher_info['from_name']); $data['text_message'] = $this->language->get('text_message'); $data['text_redeem'] = sprintf($this->language->get('text_redeem'), $voucher_info['code']); - $data['text_footer'] = $this->language->get('text_footer'); - - $this->load->model('sale/voucher_theme'); + $data['text_footer'] = $this->language->get('text_footer'); $voucher_theme_info = $this->model_sale_voucher_theme->getVoucherTheme($voucher_info['voucher_theme_id']); - + if ($voucher_theme_info && is_file(DIR_IMAGE . $voucher_theme_info['image'])) { $data['image'] = HTTP_CATALOG . 'image/' . $voucher_theme_info['image']; } else { $data['image'] = ''; } - + $data['store_name'] = $this->config->get('config_name'); $data['store_url'] = HTTP_CATALOG; $data['message'] = nl2br($voucher_info['message']); diff --git a/upload/admin/controller/setting/setting.php b/upload/admin/controller/setting/setting.php index 558b64b973a..4b2a0cbc708 100644 --- a/upload/admin/controller/setting/setting.php +++ b/upload/admin/controller/setting/setting.php @@ -317,6 +317,31 @@ public function index() { $data['config_zone_id'] = $this->config->get('config_zone_id'); } + if (isset($this->request->post['config_timezone'])) { + $data['config_timezone'] = $this->request->post['config_timezone']; + } elseif ($this->config->has('config_timezone')) { + $data['config_timezone'] = $this->config->get('config_timezone'); + } else { + $data['config_timezone'] = 'UTC'; + } + // Set Time Zone + $data['timezones'] = array(); + + $timestamp = time(); + + $timezones = timezone_identifiers_list(); + + foreach($timezones as $timezone) { + date_default_timezone_set($timezone); + $hour = ' (' . date('P', $timestamp) . ')'; + $data['timezones'][] = array( + 'text' => $timezone . $hour, + 'value' => $timezone + ); + } + + date_default_timezone_set($this->config->get('config_timezone')); + if (isset($this->request->post['config_language'])) { $data['config_language'] = $this->request->post['config_language']; } else { diff --git a/upload/admin/controller/startup/startup.php b/upload/admin/controller/startup/startup.php index c827dcb8729..87b4b708810 100644 --- a/upload/admin/controller/startup/startup.php +++ b/upload/admin/controller/startup/startup.php @@ -12,6 +12,14 @@ public function index() { } } + // Set time zone + if ($this->config->get('config_timezone')) { + date_default_timezone_set($this->config->get('config_timezone')); + + // Sync PHP and DB time zones. + $this->db->query("SET time_zone = '" . $this->db->escape(date('P')) . "'"); + } + // Theme $this->config->set('template_cache', $this->config->get('developer_theme')); diff --git a/upload/admin/language/en-gb/mail/voucher.php b/upload/admin/language/en-gb/mail/voucher.php index bc49ab6d0a0..d710b8ef9b3 100644 --- a/upload/admin/language/en-gb/mail/voucher.php +++ b/upload/admin/language/en-gb/mail/voucher.php @@ -6,4 +6,5 @@ $_['text_from'] = 'This Gift Certificate has been sent to you by %s'; $_['text_message'] = 'With a message saying'; $_['text_redeem'] = 'To redeem this Gift Certificate, write down the redemption code which is %s then click on the the link below and purchase the product you wish to use this gift certificate on. You can enter the gift certificate code on the shopping cart page before you click checkout.'; -$_['text_footer'] = 'Please reply to this email if you have any questions.'; \ No newline at end of file +$_['text_footer'] = 'Please reply to this email if you have any questions.'; +$_['text_sent'] = 'Success: Gift Voucher e-mail has been sent!'; \ No newline at end of file diff --git a/upload/admin/language/en-gb/sale/voucher.php b/upload/admin/language/en-gb/sale/voucher.php index 619849e003d..46d544be639 100644 --- a/upload/admin/language/en-gb/sale/voucher.php +++ b/upload/admin/language/en-gb/sale/voucher.php @@ -7,7 +7,6 @@ $_['text_list'] = 'Gift Voucher List'; $_['text_add'] = 'Add Gift Voucher'; $_['text_edit'] = 'Edit Gift Voucher'; -$_['text_sent'] = 'Success: Gift Voucher e-mail has been sent!'; // Column $_['column_name'] = 'Voucher Name'; diff --git a/upload/admin/language/en-gb/setting/setting.php b/upload/admin/language/en-gb/setting/setting.php index a460bff43e7..9c5ed3f3204 100644 --- a/upload/admin/language/en-gb/setting/setting.php +++ b/upload/admin/language/en-gb/setting/setting.php @@ -52,6 +52,7 @@ $_['entry_location'] = 'Store Location'; $_['entry_country'] = 'Country'; $_['entry_zone'] = 'Region / State'; +$_['entry_timezone'] = 'Time Zone'; $_['entry_language'] = 'Language'; $_['entry_admin_language'] = 'Administration Language'; $_['entry_currency'] = 'Currency'; diff --git a/upload/admin/model/catalog/product.php b/upload/admin/model/catalog/product.php index 7d3c0beaa0a..f5a26984872 100644 --- a/upload/admin/model/catalog/product.php +++ b/upload/admin/model/catalog/product.php @@ -493,7 +493,7 @@ public function getProductAttributes($product_id) { public function getProductOptions($product_id) { $product_option_data = array(); - $product_option_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_option` po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN `" . DB_PREFIX . "option_description` od ON (o.option_id = od.option_id) WHERE po.product_id = '" . (int)$product_id . "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "'"); + $product_option_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_option` po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN `" . DB_PREFIX . "option_description` od ON (o.option_id = od.option_id) WHERE po.product_id = '" . (int)$product_id . "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY o.sort_order ASC"); foreach ($product_option_query->rows as $product_option) { $product_option_value_data = array(); diff --git a/upload/admin/model/customer/customer.php b/upload/admin/model/customer/customer.php index ea611a0a9af..826648af318 100644 --- a/upload/admin/model/customer/customer.php +++ b/upload/admin/model/customer/customer.php @@ -231,7 +231,7 @@ public function getAddresses($customer_id) { } public function getTotalCustomers($data = array()) { - $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer"; + $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer c"; $implode = array(); diff --git a/upload/admin/model/localisation/tax_class.php b/upload/admin/model/localisation/tax_class.php index 43b2164d68c..c7f60d253ff 100644 --- a/upload/admin/model/localisation/tax_class.php +++ b/upload/admin/model/localisation/tax_class.php @@ -92,7 +92,7 @@ public function getTotalTaxClasses() { } public function getTaxRules($tax_class_id) { - $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "tax_rule WHERE tax_class_id = '" . (int)$tax_class_id . "'"); + $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "tax_rule WHERE tax_class_id = '" . (int)$tax_class_id . "' ORDER BY priority ASC"); return $query->rows; } diff --git a/upload/admin/model/tool/backup.php b/upload/admin/model/tool/backup.php index d8be77421ba..3640a3012f2 100644 --- a/upload/admin/model/tool/backup.php +++ b/upload/admin/model/tool/backup.php @@ -6,63 +6,41 @@ public function getTables() { $query = $this->db->query("SHOW TABLES FROM `" . DB_DATABASE . "`"); foreach ($query->rows as $result) { - if (utf8_substr($result['Tables_in_' . DB_DATABASE], 0, strlen(DB_PREFIX)) == DB_PREFIX) { - if (isset($result['Tables_in_' . DB_DATABASE])) { - $table_data[] = $result['Tables_in_' . DB_DATABASE]; - } + $table = reset($result); + if ($table && utf8_substr($table, 0, strlen(DB_PREFIX)) == DB_PREFIX) { + $table_data[] = $table; } } return $table_data; } - public function backup($tables) { - $output = ''; - foreach ($tables as $table) { - if (DB_PREFIX) { - if (strpos($table, DB_PREFIX) === false) { - $status = false; - } else { - $status = true; - } - } else { - $status = true; - } - - if ($status) { - $output .= 'TRUNCATE TABLE `' . $table . '`;' . "\n\n"; - - $query = $this->db->query("SELECT * FROM `" . $table . "`"); - - foreach ($query->rows as $result) { - $fields = ''; - - foreach (array_keys($result) as $value) { - $fields .= '`' . $value . '`, '; - } + public function getRecords($table, $start = 0, $limit = 100) { + if ($start < 0) { + $start = 0; + } - $values = ''; + if ($limit < 1) { + $limit = 10; + } - foreach (array_values($result) as $value) { - $value = str_replace(array("\x00", "\x0a", "\x0d", "\x1a"), array('\0', '\n', '\r', '\Z'), $value); - $value = str_replace(array("\n", "\r", "\t"), array('\n', '\r', '\t'), $value); - $value = str_replace('\\', '\\\\', $value); - $value = str_replace('\'', '\\\'', $value); - $value = str_replace('\\\n', '\n', $value); - $value = str_replace('\\\r', '\r', $value); - $value = str_replace('\\\t', '\t', $value); + $query = $this->db->query("SELECT * FROM `" . $table . "` LIMIT " . (int)$start . "," . (int)$limit); - $values .= '\'' . $value . '\', '; - } + if ($query->num_rows) { + return $query->rows; + } else { + return array(); + } + } - $output .= 'INSERT INTO `' . $table . '` (' . preg_replace('/, $/', '', $fields) . ') VALUES (' . preg_replace('/, $/', '', $values) . ');' . "\n"; - } + public function getTotalRecords($table) { + $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . $table . "`"); - $output .= "\n\n"; - } + if ($query->num_rows) { + return $query->row['total']; + } else { + return 0; } - - return $output; } } \ No newline at end of file diff --git a/upload/admin/model/user/api.php b/upload/admin/model/user/api.php index 993451fb3fd..194af109904 100644 --- a/upload/admin/model/user/api.php +++ b/upload/admin/model/user/api.php @@ -117,7 +117,7 @@ public function deleteApiSession($api_session_id) { $this->db->query("DELETE FROM `" . DB_PREFIX . "api_session` WHERE api_session_id = '" . (int)$api_session_id . "'"); } - public function deleteApiSessionBySessonId($session_id) { + public function deleteApiSessionBySessionId($session_id) { $this->db->query("DELETE FROM `" . DB_PREFIX . "api_session` WHERE session_id = '" . $this->db->escape($session_id) . "'"); } } diff --git a/upload/admin/view/template/common/header.twig b/upload/admin/view/template/common/header.twig index acbccd449cf..6f24b3d666b 100644 --- a/upload/admin/view/template/common/header.twig +++ b/upload/admin/view/template/common/header.twig @@ -35,14 +35,8 @@
+ \ No newline at end of file diff --git a/upload/admin/view/template/common/security.twig b/upload/admin/view/template/common/security.twig index 8588e0475da..13186ded6e9 100644 --- a/upload/admin/view/template/common/security.twig +++ b/upload/admin/view/template/common/security.twig @@ -130,8 +130,6 @@ $('#modal-security select[name=\'type\']').on('change', function () { html += '

define(\'DIR_STORAGE\', DIR_SYSTEM . \'storage/\');

'; html += '

to

'; html += '

define(\'DIR_STORAGE\', \'' + $('#modal-security input[name=\'path\']').val() + $('#modal-security input[name=\'directory\']').val() + '/\');

'; - - html += ''; html += ''; $('#collapse-manual .form-control').html(html); diff --git a/upload/admin/view/template/customer/customer_form.twig b/upload/admin/view/template/customer/customer_form.twig index 38b5dbd6b80..4765f265f6d 100644 --- a/upload/admin/view/template/customer/customer_form.twig +++ b/upload/admin/view/template/customer/customer_form.twig @@ -286,7 +286,7 @@
- +
+
{% endif %} diff --git a/upload/admin/view/template/setting/setting.twig b/upload/admin/view/template/setting/setting.twig index 3ce75f8657b..aa32ca52993 100644 --- a/upload/admin/view/template/setting/setting.twig +++ b/upload/admin/view/template/setting/setting.twig @@ -217,6 +217,20 @@ +
+ +
+ +
+
diff --git a/upload/catalog/controller/account/voucher.php b/upload/catalog/controller/account/voucher.php index 8370588db57..10858b6cb5d 100644 --- a/upload/catalog/controller/account/voucher.php +++ b/upload/catalog/controller/account/voucher.php @@ -13,7 +13,7 @@ public function index() { if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { $this->session->data['vouchers'][mt_rand()] = array( - 'description' => sprintf($this->language->get('text_for'), $this->currency->format($this->request->post['amount'], $this->session->data['currency']), $this->request->post['to_name']), + 'description' => sprintf($this->language->get('text_for'), $this->currency->format($this->request->post['amount'], $this->session->data['currency'], 1.0), $this->request->post['to_name']), 'to_name' => $this->request->post['to_name'], 'to_email' => $this->request->post['to_email'], 'from_name' => $this->request->post['from_name'], @@ -205,7 +205,7 @@ protected function validate() { $this->error['theme'] = $this->language->get('error_theme'); } - if (($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) < $this->config->get('config_voucher_min')) || ($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) > $this->config->get('config_voucher_max'))) { + if ((!isset($this->request->post['amount'])) || (!is_numeric($this->request->post['amount'])) || ($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) < $this->config->get('config_voucher_min')) || ($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) > $this->config->get('config_voucher_max'))) { $this->error['amount'] = sprintf($this->language->get('error_amount'), $this->currency->format($this->config->get('config_voucher_min'), $this->session->data['currency']), $this->currency->format($this->config->get('config_voucher_max'), $this->session->data['currency'])); } diff --git a/upload/catalog/controller/common/cart.php b/upload/catalog/controller/common/cart.php index ebe9e5e37dd..bca03a94fcd 100644 --- a/upload/catalog/controller/common/cart.php +++ b/upload/catalog/controller/common/cart.php @@ -58,7 +58,7 @@ public function index() { if ($product['image']) { $image = $this->model_tool_image->resize($product['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_height')); } else { - $image = ''; + $image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_height')); } $option_data = array(); diff --git a/upload/catalog/controller/extension/payment/eway.php b/upload/catalog/controller/extension/payment/eway.php index 393d04ae9b4..00c08e8b57f 100644 --- a/upload/catalog/controller/extension/payment/eway.php +++ b/upload/catalog/controller/extension/payment/eway.php @@ -84,7 +84,7 @@ public function index() { $item->SKU = (string)substr($product['product_id'], 0, 12); $item->Description = (string)substr($product['name'], 0, 26); $item->Quantity = strval($product['quantity']); - $item->UnitCost = strval($item_price * 100); + $item->UnitCost = $this->lowestDenomination($item_price, $order_info['currency_code']); $item->Total = $this->lowestDenomination($item_total, $order_info['currency_code']); $request->Items[] = $item; diff --git a/upload/catalog/controller/startup/startup.php b/upload/catalog/controller/startup/startup.php index a650ab72525..0f511b6b8b1 100644 --- a/upload/catalog/controller/startup/startup.php +++ b/upload/catalog/controller/startup/startup.php @@ -32,6 +32,14 @@ public function index() { } } + // Set time zone + if ($this->config->get('config_timezone')) { + date_default_timezone_set($this->config->get('config_timezone')); + + // Sync PHP and DB time zones. + $this->db->query("SET time_zone = '" . $this->db->escape(date('P')) . "'"); + } + // Theme $this->config->set('template_cache', $this->config->get('developer_theme')); @@ -188,4 +196,4 @@ public function index() { // Encryption $this->registry->set('encryption', new Encryption($this->config->get('config_encryption'))); } -} +} \ No newline at end of file diff --git a/upload/install/controller/install/step_3.php b/upload/install/controller/install/step_3.php index eb7cccd63c2..e91710c3595 100644 --- a/upload/install/controller/install/step_3.php +++ b/upload/install/controller/install/step_3.php @@ -10,6 +10,7 @@ public function index() { $this->model_install_install->database($this->request->post); + // Catalog config.php $output = 'request->post['db_driver']) . '\');' . "\n"; $output .= 'define(\'DB_HOSTNAME\', \'' . addslashes($this->request->post['db_hostname']) . '\');' . "\n"; @@ -80,7 +82,7 @@ public function index() { $output .= 'define(\'DB_DATABASE\', \'' . addslashes($this->request->post['db_database']) . '\');' . "\n"; $output .= 'define(\'DB_PORT\', \'' . addslashes($this->request->post['db_port']) . '\');' . "\n"; $output .= 'define(\'DB_PREFIX\', \'' . addslashes($this->request->post['db_prefix']) . '\');' . "\n\n"; - + $output .= '// OpenCart API' . "\n"; $output .= 'define(\'OPENCART_SERVER\', \'https://www.opencart.com/\');' . "\n"; @@ -124,6 +126,12 @@ public function index() { $data['error_warning'] = ''; } + if (isset($this->error['db_driver'])) { + $data['error_db_driver'] = $this->error['db_driver']; + } else { + $data['error_db_driver'] = ''; + } + if (isset($this->error['db_hostname'])) { $data['error_db_hostname'] = $this->error['db_hostname']; } else { @@ -174,6 +182,23 @@ public function index() { $data['action'] = $this->url->link('install/step_3'); + $db_drivers = array( + 'mysqli', + 'pdo', + 'pgsql' + ); + + $data['drivers'] = array(); + + foreach ($db_drivers as $db_driver) { + if (extension_loaded($db_driver)) { + $data['drivers'][] = array( + 'text' => $this->language->get('text_' . $db_driver), + 'value' => $db_driver + ); + } + } + if (isset($this->request->post['db_driver'])) { $data['db_driver'] = $this->request->post['db_driver']; } else { @@ -203,7 +228,7 @@ public function index() { } else { $data['db_database'] = ''; } - + if (isset($this->request->post['db_port'])) { $data['db_port'] = $this->request->post['db_port']; } else { @@ -234,11 +259,6 @@ public function index() { $data['email'] = ''; } - $data['mysqli'] = extension_loaded('mysqli'); - $data['mysql'] = extension_loaded('mysql'); - $data['pdo'] = extension_loaded('pdo'); - $data['pgsql'] = extension_loaded('pgsql'); - $data['back'] = $this->url->link('install/step_2'); $data['footer'] = $this->load->controller('common/footer'); @@ -263,46 +283,40 @@ private function validate() { if (!$this->request->post['db_port']) { $this->error['db_port'] = $this->language->get('error_db_port'); - } + } - if ($this->request->post['db_prefix'] && preg_match('/[^a-z0-9_]/', $this->request->post['db_prefix'])) { + if ($this->request->post['db_prefix'] && preg_match('/[^a-z0-9_]/', $this->request->post['db_prefix'])) { $this->error['db_prefix'] = $this->language->get('error_db_prefix'); } - if ($this->request->post['db_driver'] == 'mysqli') { - try { - $db = new \DB\MySQLi($this->request->post['db_hostname'], $this->request->post['db_username'], html_entity_decode($this->request->post['db_password'], ENT_QUOTES, 'UTF-8'), $this->request->post['db_database'], $this->request->post['db_port']); - - if (is_resource($db)) { - $db->close(); - } - } catch(Exception $e) { - $this->error['warning'] = $mysql->connect_error; - } - } elseif ($this->request->post['db_driver'] == 'mpdo') { + $db_drivers = array( + 'mysqli', + 'pdo', + 'pgsql' + ); + + if (!in_array($this->request->post['db_driver'], $db_drivers)) { + $this->error['db_driver'] = $this->language->get('error_db_driver'); + } else { try { - $db = new \DB\mPDO($this->request->post['db_hostname'], $this->request->post['db_username'], html_entity_decode($this->request->post['db_password'], ENT_QUOTES, 'UTF-8'), $this->request->post['db_database'], $this->request->post['db_port']); - - if (is_resource($db)) { - $db->close(); - } + $db = new \DB($this->request->post['db_driver'], html_entity_decode($this->request->post['db_hostname'], ENT_QUOTES, 'UTF-8'), html_entity_decode($this->request->post['db_username'], ENT_QUOTES, 'UTF-8'), html_entity_decode($this->request->post['db_password'], ENT_QUOTES, 'UTF-8'), html_entity_decode($this->request->post['db_database'], ENT_QUOTES, 'UTF-8'), $this->request->post['db_port']); } catch(Exception $e) { $this->error['warning'] = $e->getMessage(); } - } - - if (!$this->request->post['username']) { - $this->error['username'] = $this->language->get('error_username'); } - if (!$this->request->post['password']) { - $this->error['password'] = $this->language->get('error_password'); + if (!$this->request->post['username']) { + $this->error['username'] = $this->language->get('error_username'); } if ((utf8_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) { $this->error['email'] = $this->language->get('error_email'); } + if (!$this->request->post['password']) { + $this->error['password'] = $this->language->get('error_password'); + } + if (!is_writable(DIR_OPENCART . 'config.php')) { $this->error['warning'] = $this->language->get('error_config') . DIR_OPENCART . 'config.php!'; } @@ -313,4 +327,4 @@ private function validate() { return !$this->error; } -} +} \ No newline at end of file diff --git a/upload/install/language/en-gb/install/step_3.php b/upload/install/language/en-gb/install/step_3.php index 02eb28908dd..0572e136ea9 100644 --- a/upload/install/language/en-gb/install/step_3.php +++ b/upload/install/language/en-gb/install/step_3.php @@ -7,8 +7,7 @@ $_['text_db_connection'] = '1. Please enter your database connection details.'; $_['text_db_administration'] = '2. Please enter a username and password for the administration.'; $_['text_mysqli'] = 'MySQLi'; -$_['text_mysql'] = 'MySQL'; -$_['text_mpdo'] = 'mPDO'; +$_['text_pdo'] = 'mPDO'; $_['text_pgsql'] = 'PostgreSQL'; // Entry @@ -24,6 +23,7 @@ $_['entry_email'] = 'E-Mail'; // Error +$_['error_db_driver'] = 'Database Driver required!'; $_['error_db_hostname'] = 'Hostname required!'; $_['error_db_username'] = 'Username required!'; $_['error_db_database'] = 'Database Name required!'; @@ -32,5 +32,5 @@ $_['error_db_connect'] = 'Error: Could not connect to the database please make sure the database server, username and password is correct!'; $_['error_username'] = 'Username required!'; $_['error_password'] = 'Password required!'; -$_['error_email'] = 'Invalid E-Mail!'; -$_['error_config'] = 'Error: Could not write to config.php please check you have set the correct permissions on: '; +$_['error_email'] = 'E-Mail Address does not appear to be valid!'; +$_['error_config'] = 'Error: Could not write to config.php please check you have set the correct permissions on: '; \ No newline at end of file diff --git a/upload/install/opencart.sql b/upload/install/opencart.sql index 926cd4eb4f3..2b2605148ba 100644 --- a/upload/install/opencart.sql +++ b/upload/install/opencart.sql @@ -3347,8 +3347,6 @@ INSERT INTO `oc_setting` (`store_id`, `code`, `key`, `value`, `serialized`) VALU (0, 'config', 'config_robots', 'abot\r\ndbot\r\nebot\r\nhbot\r\nkbot\r\nlbot\r\nmbot\r\nnbot\r\nobot\r\npbot\r\nrbot\r\nsbot\r\ntbot\r\nvbot\r\nybot\r\nzbot\r\nbot.\r\nbot/\r\n_bot\r\n.bot\r\n/bot\r\n-bot\r\n:bot\r\n(bot\r\ncrawl\r\nslurp\r\nspider\r\nseek\r\naccoona\r\nacoon\r\nadressendeutschland\r\nah-ha.com\r\nahoy\r\naltavista\r\nananzi\r\nanthill\r\nappie\r\narachnophilia\r\narale\r\naraneo\r\naranha\r\narchitext\r\naretha\r\narks\r\nasterias\r\natlocal\r\natn\r\natomz\r\naugurfind\r\nbackrub\r\nbannana_bot\r\nbaypup\r\nbdfetch\r\nbig brother\r\nbiglotron\r\nbjaaland\r\nblackwidow\r\nblaiz\r\nblog\r\nblo.\r\nbloodhound\r\nboitho\r\nbooch\r\nbradley\r\nbutterfly\r\ncalif\r\ncassandra\r\nccubee\r\ncfetch\r\ncharlotte\r\nchurl\r\ncienciaficcion\r\ncmc\r\ncollective\r\ncomagent\r\ncombine\r\ncomputingsite\r\ncsci\r\ncurl\r\ncusco\r\ndaumoa\r\ndeepindex\r\ndelorie\r\ndepspid\r\ndeweb\r\ndie blinde kuh\r\ndigger\r\nditto\r\ndmoz\r\ndocomo\r\ndownload express\r\ndtaagent\r\ndwcp\r\nebiness\r\nebingbong\r\ne-collector\r\nejupiter\r\nemacs-w3 search engine\r\nesther\r\nevliya celebi\r\nezresult\r\nfalcon\r\nfelix ide\r\nferret\r\nfetchrover\r\nfido\r\nfindlinks\r\nfireball\r\nfish search\r\nfouineur\r\nfunnelweb\r\ngazz\r\ngcreep\r\ngenieknows\r\ngetterroboplus\r\ngeturl\r\nglx\r\ngoforit\r\ngolem\r\ngrabber\r\ngrapnel\r\ngralon\r\ngriffon\r\ngromit\r\ngrub\r\ngulliver\r\nhamahakki\r\nharvest\r\nhavindex\r\nhelix\r\nheritrix\r\nhku www octopus\r\nhomerweb\r\nhtdig\r\nhtml index\r\nhtml_analyzer\r\nhtmlgobble\r\nhubater\r\nhyper-decontextualizer\r\nia_archiver\r\nibm_planetwide\r\nichiro\r\niconsurf\r\niltrovatore\r\nimage.kapsi.net\r\nimagelock\r\nincywincy\r\nindexer\r\ninfobee\r\ninformant\r\ningrid\r\ninktomisearch.com\r\ninspector web\r\nintelliagent\r\ninternet shinchakubin\r\nip3000\r\niron33\r\nisraeli-search\r\nivia\r\njack\r\njakarta\r\njavabee\r\njetbot\r\njumpstation\r\nkatipo\r\nkdd-explorer\r\nkilroy\r\nknowledge\r\nkototoi\r\nkretrieve\r\nlabelgrabber\r\nlachesis\r\nlarbin\r\nlegs\r\nlibwww\r\nlinkalarm\r\nlink validator\r\nlinkscan\r\nlockon\r\nlwp\r\nlycos\r\nmagpie\r\nmantraagent\r\nmapoftheinternet\r\nmarvin/\r\nmattie\r\nmediafox\r\nmediapartners\r\nmercator\r\nmerzscope\r\nmicrosoft url control\r\nminirank\r\nmiva\r\nmj12\r\nmnogosearch\r\nmoget\r\nmonster\r\nmoose\r\nmotor\r\nmultitext\r\nmuncher\r\nmuscatferret\r\nmwd.search\r\nmyweb\r\nnajdi\r\nnameprotect\r\nnationaldirectory\r\nnazilla\r\nncsa beta\r\nnec-meshexplorer\r\nnederland.zoek\r\nnetcarta webmap engine\r\nnetmechanic\r\nnetresearchserver\r\nnetscoop\r\nnewscan-online\r\nnhse\r\nnokia6682/\r\nnomad\r\nnoyona\r\nnutch\r\nnzexplorer\r\nobjectssearch\r\noccam\r\nomni\r\nopen text\r\nopenfind\r\nopenintelligencedata\r\norb search\r\nosis-project\r\npack rat\r\npageboy\r\npagebull\r\npage_verifier\r\npanscient\r\nparasite\r\npartnersite\r\npatric\r\npear.\r\npegasus\r\nperegrinator\r\npgp key agent\r\nphantom\r\nphpdig\r\npicosearch\r\npiltdownman\r\npimptrain\r\npinpoint\r\npioneer\r\npiranha\r\nplumtreewebaccessor\r\npogodak\r\npoirot\r\npompos\r\npoppelsdorf\r\npoppi\r\npopular iconoclast\r\npsycheclone\r\npublisher\r\npython\r\nrambler\r\nraven search\r\nroach\r\nroad runner\r\nroadhouse\r\nrobbie\r\nrobofox\r\nrobozilla\r\nrules\r\nsalty\r\nsbider\r\nscooter\r\nscoutjet\r\nscrubby\r\nsearch.\r\nsearchprocess\r\nsemanticdiscovery\r\nsenrigan\r\nsg-scout\r\nshai''hulud\r\nshark\r\nshopwiki\r\nsidewinder\r\nsift\r\nsilk\r\nsimmany\r\nsite searcher\r\nsite valet\r\nsitetech-rover\r\nskymob.com\r\nsleek\r\nsmartwit\r\nsna-\r\nsnappy\r\nsnooper\r\nsohu\r\nspeedfind\r\nsphere\r\nsphider\r\nspinner\r\nspyder\r\nsteeler/\r\nsuke\r\nsuntek\r\nsupersnooper\r\nsurfnomore\r\nsven\r\nsygol\r\nszukacz\r\ntach black widow\r\ntarantula\r\ntempleton\r\n/teoma\r\nt-h-u-n-d-e-r-s-t-o-n-e\r\ntheophrastus\r\ntitan\r\ntitin\r\ntkwww\r\ntoutatis\r\nt-rex\r\ntutorgig\r\ntwiceler\r\ntwisted\r\nucsd\r\nudmsearch\r\nurl check\r\nupdated\r\nvagabondo\r\nvalkyrie\r\nverticrawl\r\nvictoria\r\nvision-search\r\nvolcano\r\nvoyager/\r\nvoyager-hc\r\nw3c_validator\r\nw3m2\r\nw3mir\r\nwalker\r\nwallpaper\r\nwanderer\r\nwauuu\r\nwavefire\r\nweb core\r\nweb hopper\r\nweb wombat\r\nwebbandit\r\nwebcatcher\r\nwebcopy\r\nwebfoot\r\nweblayers\r\nweblinker\r\nweblog monitor\r\nwebmirror\r\nwebmonkey\r\nwebquest\r\nwebreaper\r\nwebsitepulse\r\nwebsnarf\r\nwebstolperer\r\nwebvac\r\nwebwalk\r\nwebwatch\r\nwebwombat\r\nwebzinger\r\nwhizbang\r\nwhowhere\r\nwild ferret\r\nworldlight\r\nwwwc\r\nwwwster\r\nxenu\r\nxget\r\nxift\r\nxirq\r\nyandex\r\nyanga\r\nyeti\r\nyodao\r\nzao\r\nzippp\r\nzyborg', 0), (0, 'config', 'config_shared', '0', 0), (0, 'config', 'config_secure', '0', 0), -(0, 'total_voucher', 'total_voucher_sort_order', '8', 0), -(0, 'total_voucher', 'total_voucher_status', '1', 0), (0, 'config', 'config_fraud_detection', '0', 0), (0, 'config', 'config_ftp_status', '0', 0), (0, 'config', 'config_ftp_root', '', 0), @@ -3363,6 +3361,7 @@ INSERT INTO `oc_setting` (`store_id`, `code`, `key`, `value`, `serialized`) VALU (0, 'config', 'config_layout_id', '4', 0), (0, 'config', 'config_country_id', '222', 0), (0, 'config', 'config_zone_id', '3563', 0), +(0, 'config', 'config_timezone', 'UTC', 0), (0, 'config', 'config_language', 'en-gb', 0), (0, 'config', 'config_admin_language', 'en-gb', 0), (0, 'config', 'config_currency', 'USD', 0), @@ -3385,7 +3384,7 @@ INSERT INTO `oc_setting` (`store_id`, `code`, `key`, `value`, `serialized`) VALU (0, 'config', 'config_customer_group_display', '["1"]', 1), (0, 'config', 'config_customer_price', '0', 0), (0, 'config', 'config_account_id', '3', 0), -(0, 'config', 'config_invoice_prefix', 'INV-2013-00', 0), +(0, 'config', 'config_invoice_prefix', CONCAT('INV-', YEAR(CURDATE()), '-00'), 0), (0, 'config', 'config_api_id', '1', 0), (0, 'config', 'config_cart_weight', '1', 0), (0, 'config', 'config_checkout_guest', '1', 0), @@ -3439,7 +3438,7 @@ INSERT INTO `oc_setting` (`store_id`, `code`, `key`, `value`, `serialized`) VALU (0, 'config', 'config_captcha_page', '["review","return","contact"]', 1), (0, 'config', 'config_login_attempts', '5', 0), (0, 'payment_free_checkout', 'payment_free_checkout_status', '1', 0), -(0, 'payment_free_checkout', 'free_checkout_order_status_id', '1', 0), +(0, 'payment_free_checkout', 'payment_free_checkout_order_status_id', '1', 0), (0, 'payment_free_checkout', 'payment_free_checkout_sort_order', '1', 0), (0, 'payment_cod', 'payment_cod_sort_order', '5', 0), (0, 'payment_cod', 'payment_cod_total', '0.01', 0), @@ -3466,6 +3465,8 @@ INSERT INTO `oc_setting` (`store_id`, `code`, `key`, `value`, `serialized`) VALU (0, 'total_shipping', 'total_shipping_estimator', '1', 0), (0, 'total_coupon', 'total_coupon_sort_order', '4', 0), (0, 'total_coupon', 'total_coupon_status', '1', 0), +(0, 'total_voucher', 'total_voucher_sort_order', '8', 0), +(0, 'total_voucher', 'total_voucher_status', '1', 0), (0, 'module_category', 'module_category_status', '1', 0), (0, 'module_account', 'module_account_status', '1', 0), (0, 'theme_default', 'theme_default_product_limit', '15', 0), diff --git a/upload/install/view/template/install/step_3.twig b/upload/install/view/template/install/step_3.twig index cb448061a6b..8ec87ad8ea8 100644 --- a/upload/install/view/template/install/step_3.twig +++ b/upload/install/view/template/install/step_3.twig @@ -3,19 +3,23 @@
-

3/4

-

{{ heading_title }}
- {{ text_step_3 }}

+

3 + /4 +

+

{{ heading_title }} +
+ {{ text_step_3 }} +

- +
{% if error_warning %} -
{{ error_warning }} - -
+
{{ error_warning }} + +
{% endif %}
@@ -26,78 +30,67 @@
+ {% if error_db_driver %} +
{{ error_db_driver }}
+ {% endif %}
- + {% if error_db_hostname %} -
{{ error_db_hostname }}
+
{{ error_db_hostname }}
{% endif %}
- + {% if error_db_username %} -
{{ error_db_username }}
+
{{ error_db_username }}
{% endif %}
- +
- + {% if error_db_database %} -
{{ error_db_database }}
+
{{ error_db_database }}
{% endif %}
- + {% if error_db_port %} -
{{ error_db_port }}
+
{{ error_db_port }}
{% endif %}
- + {% if error_db_prefix %} -
{{ error_db_prefix }}
+
{{ error_db_prefix }}
{% endif %}
@@ -107,27 +100,27 @@
- + {% if error_username %} -
{{ error_username }}
+
{{ error_username }}
{% endif %}
- + {% if error_password %} -
{{ error_password }}
+
{{ error_password }}
{% endif %}
- + {% if error_email %} -
{{ error_email }}
+
{{ error_email }}
{% endif %}
@@ -135,7 +128,7 @@ diff --git a/upload/system/config/admin.php b/upload/system/config/admin.php index 56b6ef0cef4..8efe8f04d40 100644 --- a/upload/system/config/admin.php +++ b/upload/system/config/admin.php @@ -5,7 +5,7 @@ // Database $_['db_autostart'] = true; -$_['db_engine'] = DB_DRIVER; // mpdo, mssql, mysql, mysqli or postgre +$_['db_engine'] = DB_DRIVER; // mpdo, mysqli or postgre $_['db_hostname'] = DB_HOSTNAME; $_['db_username'] = DB_USERNAME; $_['db_password'] = DB_PASSWORD; @@ -46,4 +46,4 @@ 'view/*/before' => array( 'event/language' ) -); +); \ No newline at end of file diff --git a/upload/system/config/catalog.php b/upload/system/config/catalog.php index 1385152ba6f..7bb0d2f9106 100644 --- a/upload/system/config/catalog.php +++ b/upload/system/config/catalog.php @@ -8,7 +8,7 @@ // Database $_['db_autostart'] = true; -$_['db_engine'] = DB_DRIVER; // mpdo, mssql, mysql, mysqli or postgre +$_['db_engine'] = DB_DRIVER; // mpdo, mysqli or postgre $_['db_hostname'] = DB_HOSTNAME; $_['db_username'] = DB_USERNAME; $_['db_password'] = DB_PASSWORD; diff --git a/upload/system/config/default.php b/upload/system/config/default.php index 8a328492786..f6241ec152c 100644 --- a/upload/system/config/default.php +++ b/upload/system/config/default.php @@ -14,7 +14,7 @@ $_['date_timezone'] = 'UTC'; // Database -$_['db_engine'] = 'mysqli'; // mpdo, mssql, mysql, mysqli or postgre +$_['db_engine'] = 'mysqli'; // mpdo, mysqli or postgre $_['db_hostname'] = 'localhost'; $_['db_username'] = 'root'; $_['db_password'] = ''; diff --git a/upload/system/framework.php b/upload/system/framework.php index 7d3da23830e..3c167359eeb 100644 --- a/upload/system/framework.php +++ b/upload/system/framework.php @@ -77,7 +77,11 @@ // Database if ($config->get('db_autostart')) { - $registry->set('db', new DB($config->get('db_engine'), $config->get('db_hostname'), $config->get('db_username'), $config->get('db_password'), $config->get('db_database'), $config->get('db_port'))); + $db = new DB($config->get('db_engine'), $config->get('db_hostname'), $config->get('db_username'), $config->get('db_password'), $config->get('db_database'), $config->get('db_port')); + $registry->set('db', $db); + + // Sync PHP and DB time zones + $db->query("SET time_zone = '" . $db->escape(date('P')) . "'"); } // Session diff --git a/upload/system/library/cache/redis.php b/upload/system/library/cache/redis.php index 315f27be970..b3d2504f353 100644 --- a/upload/system/library/cache/redis.php +++ b/upload/system/library/cache/redis.php @@ -1,30 +1,33 @@ expire = $expire; - - $this->cache = new \Redis(); - $this->cache->pconnect(CACHE_HOSTNAME, CACHE_PORT); - } - - public function get($key) { - $data = $this->cache->get(CACHE_PREFIX . $key); - return json_decode($data, true); - } - - public function set($key,$value) { - $status = $this->cache->set(CACHE_PREFIX . $key, json_encode($value)); - if($status){ - $this->cache->setTimeout(CACHE_PREFIX . $key, $this->expire); - } - return $status; - } - - public function delete($key) { - $this->cache->delete(CACHE_PREFIX . $key); - } + private $expire; + private $cache; + + public function __construct($expire) { + $this->expire = $expire; + + $this->cache = new \Redis(); + $this->cache->pconnect(CACHE_HOSTNAME, CACHE_PORT); + } + + public function get($key) { + $data = $this->cache->get(CACHE_PREFIX . $key); + + return json_decode($data, true); + } + + public function set($key, $value) { + $status = $this->cache->set(CACHE_PREFIX . $key, json_encode($value)); + + if ($status) { + $this->cache->expire(CACHE_PREFIX . $key, $this->expire); + } + + return $status; + } + + public function delete($key) { + $this->cache->del(CACHE_PREFIX . $key); + } } \ No newline at end of file diff --git a/upload/system/library/mail/smtp.php b/upload/system/library/mail/smtp.php index f5f822ded13..386e4ba91aa 100644 --- a/upload/system/library/mail/smtp.php +++ b/upload/system/library/mail/smtp.php @@ -6,6 +6,7 @@ class Smtp { public $smtp_password; public $smtp_port = 25; public $smtp_timeout = 5; + public $max_attempts = 3; public $verp = false; public function send() { @@ -17,29 +18,29 @@ public function send() { $boundary = '----=_NextPart_' . md5(time()); - $header = 'MIME-Version: 1.0' . PHP_EOL; + $header = 'MIME-Version: 1.0' . PHP_EOL; $header .= 'To: <' . $to . '>' . PHP_EOL; $header .= 'Subject: =?UTF-8?B?' . base64_encode($this->subject) . '?=' . PHP_EOL; $header .= 'Date: ' . date('D, d M Y H:i:s O') . PHP_EOL; $header .= 'From: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL; - + if (!$this->reply_to) { $header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->from . '>' . PHP_EOL; } else { $header .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->reply_to) . '?= <' . $this->reply_to . '>' . PHP_EOL; } - + $header .= 'Return-Path: ' . $this->from . PHP_EOL; $header .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL; $header .= 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . PHP_EOL . PHP_EOL; if (!$this->html) { - $message = '--' . $boundary . PHP_EOL; + $message = '--' . $boundary . PHP_EOL; $message .= 'Content-Type: text/plain; charset="utf-8"' . PHP_EOL; $message .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL; $message .= $this->text . PHP_EOL; } else { - $message = '--' . $boundary . PHP_EOL; + $message = '--' . $boundary . PHP_EOL; $message .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '_alt"' . PHP_EOL . PHP_EOL; $message .= '--' . $boundary . '_alt' . PHP_EOL; $message .= 'Content-Type: text/plain; charset="utf-8"' . PHP_EOL; @@ -92,7 +93,7 @@ public function send() { if (substr(PHP_OS, 0, 3) != 'WIN') { socket_set_timeout($handle, $this->smtp_timeout, 0); } - + while ($line = fgets($handle, 515)) { if (substr($line, 3, 1) == ' ') { break; @@ -109,9 +110,9 @@ public function send() { //some SMTP servers respond with 220 code before responding with 250. hence, we need to ignore 220 response string if (substr($reply, 0, 3) == 220 && substr($line, 3, 1) == ' ') { $reply = ''; + continue; - } - else if (substr($line, 3, 1) == ' ') { + } else if (substr($line, 3, 1) == ' ') { break; } } @@ -123,137 +124,46 @@ public function send() { if (substr($this->smtp_hostname, 0, 3) == 'tls') { fputs($handle, 'STARTTLS' . "\r\n"); - $reply = ''; - - while ($line = fgets($handle, 515)) { - $reply .= $line; - - if (substr($line, 3, 1) == ' ') { - break; - } - } - - if (substr($reply, 0, 3) != 220) { - throw new \Exception('Error: STARTTLS not accepted from server!'); - } + $this->handleReply($handle, 220, 'Error: STARTTLS not accepted from server!'); stream_socket_enable_crypto($handle, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); } - if (!empty($this->smtp_username) && !empty($this->smtp_password)) { + if (!empty($this->smtp_username) && !empty($this->smtp_password)) { fputs($handle, 'EHLO ' . getenv('SERVER_NAME') . "\r\n"); - $reply = ''; - - while ($line = fgets($handle, 515)) { - $reply .= $line; - - if (substr($line, 3, 1) == ' ') { - break; - } - } - - if (substr($reply, 0, 3) != 250) { - throw new \Exception('Error: EHLO not accepted from server!'); - } + $this->handleReply($handle, 250, 'Error: EHLO not accepted from server!'); fputs($handle, 'AUTH LOGIN' . "\r\n"); - $reply = ''; - - while ($line = fgets($handle, 515)) { - $reply .= $line; - - if (substr($line, 3, 1) == ' ') { - break; - } - } - - if (substr($reply, 0, 3) != 334) { - throw new \Exception('Error: AUTH LOGIN not accepted from server!'); - } + $this->handleReply($handle, 334, 'Error: AUTH LOGIN not accepted from server!'); fputs($handle, base64_encode($this->smtp_username) . "\r\n"); - $reply = ''; - - while ($line = fgets($handle, 515)) { - $reply .= $line; - - if (substr($line, 3, 1) == ' ') { - break; - } - } - - if (substr($reply, 0, 3) != 334) { - throw new \Exception('Error: Username not accepted from server!'); - } + $this->handleReply($handle, 334, 'Error: Username not accepted from server!'); fputs($handle, base64_encode($this->smtp_password) . "\r\n"); - $reply = ''; - - while ($line = fgets($handle, 515)) { - $reply .= $line; - - if (substr($line, 3, 1) == ' ') { - break; - } - } + $this->handleReply($handle, 235, 'Error: Password not accepted from server!'); - if (substr($reply, 0, 3) != 235) { - throw new \Exception('Error: Password not accepted from server!'); - } } else { fputs($handle, 'HELO ' . getenv('SERVER_NAME') . "\r\n"); - $reply = ''; - - while ($line = fgets($handle, 515)) { - $reply .= $line; - - if (substr($line, 3, 1) == ' ') { - break; - } - } - - if (substr($reply, 0, 3) != 250) { - throw new \Exception('Error: HELO not accepted from server!'); - } + $this->handleReply($handle, 250, 'Error: HELO not accepted from server!'); } if ($this->verp) { - fputs($handle, 'MAIL FROM: <' . $this->from . '>XVERP' . "\r\n"); + fputs($handle, 'MAIL FROM: <' . $this->smtp_username . '>XVERP' . "\r\n"); } else { - fputs($handle, 'MAIL FROM: <' . $this->from . '>' . "\r\n"); + fputs($handle, 'MAIL FROM: <' . $this->smtp_username . '>' . "\r\n"); } - $reply = ''; - - while ($line = fgets($handle, 515)) { - $reply .= $line; - - if (substr($line, 3, 1) == ' ') { - break; - } - } - - if (substr($reply, 0, 3) != 250) { - throw new \Exception('Error: MAIL FROM not accepted from server!'); - } + $this->handleReply($handle, 250, 'Error: MAIL FROM not accepted from server!'); if (!is_array($this->to)) { fputs($handle, 'RCPT TO: <' . $this->to . '>' . "\r\n"); - $reply = ''; - - while ($line = fgets($handle, 515)) { - $reply .= $line; - - if (substr($line, 3, 1) == ' ') { - break; - } - } + $reply = $this->handleReply($handle, false, 'RCPT TO [!array]'); if ((substr($reply, 0, 3) != 250) && (substr($reply, 0, 3) != 251)) { throw new \Exception('Error: RCPT TO not accepted from server!'); @@ -262,15 +172,7 @@ public function send() { foreach ($this->to as $recipient) { fputs($handle, 'RCPT TO: <' . $recipient . '>' . "\r\n"); - $reply = ''; - - while ($line = fgets($handle, 515)) { - $reply .= $line; - - if (substr($line, 3, 1) == ' ') { - break; - } - } + $reply = $this->handleReply($handle, false, 'RCPT TO [array]'); if ((substr($reply, 0, 3) != 250) && (substr($reply, 0, 3) != 251)) { throw new \Exception('Error: RCPT TO not accepted from server!'); @@ -280,28 +182,18 @@ public function send() { fputs($handle, 'DATA' . "\r\n"); - $reply = ''; - - while ($line = fgets($handle, 515)) { - $reply .= $line; - - if (substr($line, 3, 1) == ' ') { - break; - } - } - - if (substr($reply, 0, 3) != 354) { - throw new \Exception('Error: DATA not accepted from server!'); - } + $this->handleReply($handle, 354, 'Error: DATA not accepted from server!'); // According to rfc 821 we should not send more than 1000 including the CRLF $message = str_replace("\r\n", "\n", $header . $message); $message = str_replace("\r", "\n", $message); + $length = (mb_detect_encoding($message, mb_detect_order(), true) == 'ASCII') ? 998 : 249; + $lines = explode("\n", $message); foreach ($lines as $line) { - $results = str_split($line, 998); + $results = str_split($line, $length); foreach ($results as $result) { if (substr(PHP_OS, 0, 3) != 'WIN') { @@ -314,37 +206,42 @@ public function send() { fputs($handle, '.' . "\r\n"); - $reply = ''; - - while ($line = fgets($handle, 515)) { - $reply .= $line; + $this->handleReply($handle, 250, 'Error: DATA not accepted from server!'); - if (substr($line, 3, 1) == ' ') { - break; - } - } + fputs($handle, 'QUIT' . "\r\n"); - if (substr($reply, 0, 3) != 250) { - throw new \Exception('Error: DATA not accepted from server!'); - } + $this->handleReply($handle, 221, 'Error: QUIT not accepted from server!'); - fputs($handle, 'QUIT' . "\r\n"); + fclose($handle); + } + } - $reply = ''; + private function handleReply($handle, $status_code = false, $error_text = false, $counter = 0) { + $reply = ''; - while ($line = fgets($handle, 515)) { - $reply .= $line; + while (($line = fgets($handle, 515)) !== false) { + $reply .= $line; - if (substr($line, 3, 1) == ' ') { - break; - } + if (substr($line, 3, 1) == ' ') { + break; } + } - if (substr($reply, 0, 3) != 221) { - throw new \Exception('Error: QUIT not accepted from server!'); - } + // Handle slowish server responses (generally due to policy servers) + if (!$line && empty($reply) && $counter < $this->max_attempts) { + sleep(1); - fclose($handle); + $counter++; + + return $this->handleReply($handle, $status_code, $error_text, $counter); + } + + if ($status_code) { + if (substr($reply, 0, 3) != $status_code) { + throw new \Exception($error_text); + } } + + return $reply; } } \ No newline at end of file diff --git a/upload/system/library/session/db.php b/upload/system/library/session/db.php index 99882c7f275..77439a3d7e8 100644 --- a/upload/system/library/session/db.php +++ b/upload/system/library/session/db.php @@ -1,49 +1,58 @@ db = $registry->get('db'); - - $this->expire = ini_get('session.gc_maxlifetime'); + + $this->maxlifetime = ini_get('session.gc_maxlifetime') !== null ? (int)ini_get('session.gc_maxlifetime') : 1440; + + $this->gc(); } - + public function read($session_id) { - $query = $this->db->query("SELECT `data` FROM `" . DB_PREFIX . "session` WHERE session_id = '" . $this->db->escape($session_id) . "' AND expire > " . (int)time()); - + $query = $this->db->query("SELECT `data` FROM `" . DB_PREFIX . "session` WHERE `session_id` = '" . $this->db->escape($session_id) . "' AND `expire` > '" . $this->db->escape(date('Y-m-d H:i:s', time())) . "'"); + if ($query->num_rows) { return json_decode($query->row['data'], true); } else { return false; } } - + public function write($session_id, $data) { if ($session_id) { - $this->db->query("REPLACE INTO `" . DB_PREFIX . "session` SET session_id = '" . $this->db->escape($session_id) . "', `data` = '" . $this->db->escape(json_encode($data)) . "', expire = '" . $this->db->escape(date('Y-m-d H:i:s', time() + $this->expire)) . "'"); + $this->db->query("REPLACE INTO `" . DB_PREFIX . "session` SET `session_id` = '" . $this->db->escape($session_id) . "', `data` = '" . $this->db->escape(json_encode($data)) . "', `expire` = '" . $this->db->escape(date('Y-m-d H:i:s', time() + (int)$this->maxlifetime)) . "'"); } - + return true; } - + public function destroy($session_id) { - $this->db->query("DELETE FROM `" . DB_PREFIX . "session` WHERE session_id = '" . $this->db->escape($session_id) . "'"); - + $this->db->query("DELETE FROM `" . DB_PREFIX . "session` WHERE `session_id` = '" . $this->db->escape($session_id) . "'"); + return true; } - - public function gc($expire) { - $this->db->query("DELETE FROM `" . DB_PREFIX . "session` WHERE expire < " . ((int)time() + $expire)); - - return true; + + public function gc() { + if (ini_get('session.gc_divisor') && $gc_divisor = (int)ini_get('session.gc_divisor')) { + $gc_divisor = $gc_divisor === 0 ? 100 : $gc_divisor; + } else { + $gc_divisor = 100; + } + + if (ini_get('session.gc_probability')) { + $gc_probability = (int)ini_get('session.gc_probability'); + } else { + $gc_probability = 1; + } + + if (mt_rand() / mt_getrandmax() > $gc_probability / $gc_divisor) { + $this->db->query("DELETE FROM `" . DB_PREFIX . "session` WHERE `expire` < '" . $this->db->escape(date('Y-m-d H:i:s', time())) . "'"); + + return true; + } } -} +} \ No newline at end of file