first commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* Cache class
|
||||
*/
|
||||
class Cache {
|
||||
private $adaptor;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $adaptor The type of storage for the cache.
|
||||
* @param int $expire Optional parameters
|
||||
*
|
||||
*/
|
||||
public function __construct($adaptor, $expire = 3600) {
|
||||
$class = 'Cache\\' . $adaptor;
|
||||
|
||||
if (class_exists($class)) {
|
||||
$this->adaptor = new $class($expire);
|
||||
} else {
|
||||
throw new \Exception('Error: Could not load cache adaptor ' . $adaptor . ' cache!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a cache by key name.
|
||||
*
|
||||
* @param string $key The cache key name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get($key) {
|
||||
return $this->adaptor->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $key The cache key
|
||||
* @param string $value The cache value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function set($key, $value) {
|
||||
return $this->adaptor->set($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $key The cache key
|
||||
*/
|
||||
public function delete($key) {
|
||||
return $this->adaptor->delete($key);
|
||||
}
|
||||
}
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace Cache;
|
||||
class APC {
|
||||
private $expire;
|
||||
private $active = false;
|
||||
|
||||
public function __construct($expire) {
|
||||
$this->expire = $expire;
|
||||
$this->active = function_exists('apc_cache_info') && ini_get('apc.enabled');
|
||||
}
|
||||
|
||||
public function get($key) {
|
||||
return $this->active ? apc_fetch(CACHE_PREFIX . $key) : false;
|
||||
}
|
||||
|
||||
public function set($key, $value) {
|
||||
return $this->active ? apc_store(CACHE_PREFIX . $key, $value, $this->expire) : false;
|
||||
}
|
||||
|
||||
public function delete($key) {
|
||||
if (!$this->active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cache_info = apc_cache_info('user');
|
||||
$cache_list = $cache_info['cache_list'];
|
||||
foreach ($cache_list as $entry) {
|
||||
if (strpos($entry['info'], CACHE_PREFIX . $key) === 0) {
|
||||
apcu_delete($entry['info']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace Cache;
|
||||
class File {
|
||||
private $expire;
|
||||
|
||||
public function __construct($expire = 3600) {
|
||||
$this->expire = $expire;
|
||||
|
||||
$files = glob(DIR_CACHE . 'cache.*');
|
||||
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
$filename = basename($file);
|
||||
|
||||
$time = substr(strrchr($file, '.'), 1);
|
||||
|
||||
if ($time < time()) {
|
||||
$this->delete(substr($filename, 6, strrpos($filename, '.') - 6));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get($key) {
|
||||
$files = glob(DIR_CACHE . 'cache.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.*');
|
||||
|
||||
if ($files) {
|
||||
$handle = fopen($files[0], 'r');
|
||||
|
||||
flock($handle, LOCK_SH);
|
||||
|
||||
$size = filesize($files[0]);
|
||||
|
||||
if ($size > 0) {
|
||||
$data = fread($handle, $size);
|
||||
} else {
|
||||
$data = '';
|
||||
}
|
||||
|
||||
flock($handle, LOCK_UN);
|
||||
|
||||
fclose($handle);
|
||||
|
||||
return json_decode($data, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function set($key, $value) {
|
||||
$this->delete($key);
|
||||
|
||||
$file = DIR_CACHE . 'cache.' . basename($key) . '.' . (time() + $this->expire);
|
||||
|
||||
$handle = fopen($file, 'w');
|
||||
|
||||
flock($handle, LOCK_EX);
|
||||
|
||||
fwrite($handle, json_encode($value));
|
||||
|
||||
fflush($handle);
|
||||
|
||||
flock($handle, LOCK_UN);
|
||||
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
public function delete(string $key) {
|
||||
$files = glob(DIR_CACHE . 'cache.' . basename($key) . '.*');
|
||||
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
if (!@unlink($file)) {
|
||||
clearstatcache(false, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Cache;
|
||||
class Mem {
|
||||
private $expire;
|
||||
private $memcache;
|
||||
|
||||
const CACHEDUMP_LIMIT = 9999;
|
||||
|
||||
public function __construct($expire) {
|
||||
$this->expire = $expire;
|
||||
|
||||
$this->memcache = new \Memcache();
|
||||
$this->memcache->pconnect(CACHE_HOSTNAME, CACHE_PORT);
|
||||
}
|
||||
|
||||
public function get($key) {
|
||||
return $this->memcache->get(CACHE_PREFIX . $key);
|
||||
}
|
||||
|
||||
public function set($key, $value) {
|
||||
return $this->memcache->set(CACHE_PREFIX . $key, $value, MEMCACHE_COMPRESSED, $this->expire);
|
||||
}
|
||||
|
||||
public function delete($key) {
|
||||
$this->memcache->delete(CACHE_PREFIX . $key);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Cache;
|
||||
class Memcached {
|
||||
private $expire;
|
||||
private $memcached;
|
||||
|
||||
const CACHEDUMP_LIMIT = 9999;
|
||||
|
||||
public function __construct($expire) {
|
||||
$this->expire = $expire;
|
||||
$this->memcached = new \Memcached();
|
||||
|
||||
$this->memcached->addServer(CACHE_HOSTNAME, CACHE_PORT);
|
||||
}
|
||||
|
||||
public function get($key) {
|
||||
return $this->memcached->get(CACHE_PREFIX . $key);
|
||||
}
|
||||
|
||||
public function set($key, $value) {
|
||||
return $this->memcached->set(CACHE_PREFIX . $key, $value, $this->expire);
|
||||
}
|
||||
|
||||
public function delete($key) {
|
||||
$this->memcached->delete(CACHE_PREFIX . $key);
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace Cache;
|
||||
class Redis {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
<?php
|
||||
namespace Cart;
|
||||
class Cart {
|
||||
private $data = array();
|
||||
|
||||
public function __construct($registry) {
|
||||
$this->config = $registry->get('config');
|
||||
$this->customer = $registry->get('customer');
|
||||
$this->session = $registry->get('session');
|
||||
$this->db = $registry->get('db');
|
||||
$this->tax = $registry->get('tax');
|
||||
$this->weight = $registry->get('weight');
|
||||
|
||||
// Remove all the expired carts with no customer ID
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE (api_id > '0' OR customer_id = '0') AND date_added < DATE_SUB(NOW(), INTERVAL 1 HOUR)");
|
||||
|
||||
if ($this->customer->getId()) {
|
||||
// We want to change the session ID on all the old items in the customers cart
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "cart SET session_id = '" . $this->db->escape($this->session->getId()) . "' WHERE api_id = '0' AND customer_id = '" . (int)$this->customer->getId() . "'");
|
||||
|
||||
// Once the customer is logged in we want to update the customers cart
|
||||
$cart_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '0' AND customer_id = '0' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");
|
||||
|
||||
foreach ($cart_query->rows as $cart) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart['cart_id'] . "'");
|
||||
|
||||
// The advantage of using $this->add is that it will check if the products already exist and increaser the quantity if necessary.
|
||||
$this->add($cart['product_id'], $cart['quantity'], json_decode($cart['option']), $cart['recurring_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getProducts() {
|
||||
$product_data = array();
|
||||
|
||||
$cart_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");
|
||||
|
||||
foreach ($cart_query->rows as $cart) {
|
||||
$stock = true;
|
||||
|
||||
$product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_store p2s LEFT JOIN " . DB_PREFIX . "product p ON (p2s.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND p2s.product_id = '" . (int)$cart['product_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");
|
||||
|
||||
if ($product_query->num_rows && ($cart['quantity'] > 0)) {
|
||||
$option_price = 0;
|
||||
$option_points = 0;
|
||||
$option_weight = 0;
|
||||
|
||||
$option_data = array();
|
||||
|
||||
foreach (json_decode($cart['option']) as $product_option_id => $value) {
|
||||
$option_query = $this->db->query("SELECT po.product_option_id, po.option_id, od.name, o.type 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_option_id = '" . (int)$product_option_id . "' AND po.product_id = '" . (int)$cart['product_id'] . "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
if ($option_query->num_rows) {
|
||||
if ($option_query->row['type'] == 'select' || $option_query->row['type'] == 'radio') {
|
||||
$option_value_query = $this->db->query("SELECT pov.option_value_id, ovd.name, pov.quantity, pov.subtract, pov.price, pov.price_prefix, pov.points, pov.points_prefix, pov.weight, pov.weight_prefix FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_option_value_id = '" . (int)$value . "' AND pov.product_option_id = '" . (int)$product_option_id . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
if ($option_value_query->num_rows) {
|
||||
if ($option_value_query->row['price_prefix'] == '+') {
|
||||
$option_price += $option_value_query->row['price'];
|
||||
} elseif ($option_value_query->row['price_prefix'] == '-') {
|
||||
$option_price -= $option_value_query->row['price'];
|
||||
}
|
||||
|
||||
if ($option_value_query->row['points_prefix'] == '+') {
|
||||
$option_points += $option_value_query->row['points'];
|
||||
} elseif ($option_value_query->row['points_prefix'] == '-') {
|
||||
$option_points -= $option_value_query->row['points'];
|
||||
}
|
||||
|
||||
if ($option_value_query->row['weight_prefix'] == '+') {
|
||||
$option_weight += $option_value_query->row['weight'];
|
||||
} elseif ($option_value_query->row['weight_prefix'] == '-') {
|
||||
$option_weight -= $option_value_query->row['weight'];
|
||||
}
|
||||
|
||||
if ($option_value_query->row['subtract'] && (!$option_value_query->row['quantity'] || ($option_value_query->row['quantity'] < $cart['quantity']))) {
|
||||
$stock = false;
|
||||
}
|
||||
|
||||
$option_data[] = array(
|
||||
'product_option_id' => $product_option_id,
|
||||
'product_option_value_id' => $value,
|
||||
'option_id' => $option_query->row['option_id'],
|
||||
'option_value_id' => $option_value_query->row['option_value_id'],
|
||||
'name' => $option_query->row['name'],
|
||||
'value' => $option_value_query->row['name'],
|
||||
'type' => $option_query->row['type'],
|
||||
'quantity' => $option_value_query->row['quantity'],
|
||||
'subtract' => $option_value_query->row['subtract'],
|
||||
'price' => $option_value_query->row['price'],
|
||||
'price_prefix' => $option_value_query->row['price_prefix'],
|
||||
'points' => $option_value_query->row['points'],
|
||||
'points_prefix' => $option_value_query->row['points_prefix'],
|
||||
'weight' => $option_value_query->row['weight'],
|
||||
'weight_prefix' => $option_value_query->row['weight_prefix']
|
||||
);
|
||||
}
|
||||
} elseif ($option_query->row['type'] == 'checkbox' && is_array($value)) {
|
||||
foreach ($value as $product_option_value_id) {
|
||||
$option_value_query = $this->db->query("SELECT pov.option_value_id, pov.quantity, pov.subtract, pov.price, pov.price_prefix, pov.points, pov.points_prefix, pov.weight, pov.weight_prefix, ovd.name FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (pov.option_value_id = ovd.option_value_id) WHERE pov.product_option_value_id = '" . (int)$product_option_value_id . "' AND pov.product_option_id = '" . (int)$product_option_id . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
if ($option_value_query->num_rows) {
|
||||
if ($option_value_query->row['price_prefix'] == '+') {
|
||||
$option_price += $option_value_query->row['price'];
|
||||
} elseif ($option_value_query->row['price_prefix'] == '-') {
|
||||
$option_price -= $option_value_query->row['price'];
|
||||
}
|
||||
|
||||
if ($option_value_query->row['points_prefix'] == '+') {
|
||||
$option_points += $option_value_query->row['points'];
|
||||
} elseif ($option_value_query->row['points_prefix'] == '-') {
|
||||
$option_points -= $option_value_query->row['points'];
|
||||
}
|
||||
|
||||
if ($option_value_query->row['weight_prefix'] == '+') {
|
||||
$option_weight += $option_value_query->row['weight'];
|
||||
} elseif ($option_value_query->row['weight_prefix'] == '-') {
|
||||
$option_weight -= $option_value_query->row['weight'];
|
||||
}
|
||||
|
||||
if ($option_value_query->row['subtract'] && (!$option_value_query->row['quantity'] || ($option_value_query->row['quantity'] < $cart['quantity']))) {
|
||||
$stock = false;
|
||||
}
|
||||
|
||||
$option_data[] = array(
|
||||
'product_option_id' => $product_option_id,
|
||||
'product_option_value_id' => $product_option_value_id,
|
||||
'option_id' => $option_query->row['option_id'],
|
||||
'option_value_id' => $option_value_query->row['option_value_id'],
|
||||
'name' => $option_query->row['name'],
|
||||
'value' => $option_value_query->row['name'],
|
||||
'type' => $option_query->row['type'],
|
||||
'quantity' => $option_value_query->row['quantity'],
|
||||
'subtract' => $option_value_query->row['subtract'],
|
||||
'price' => $option_value_query->row['price'],
|
||||
'price_prefix' => $option_value_query->row['price_prefix'],
|
||||
'points' => $option_value_query->row['points'],
|
||||
'points_prefix' => $option_value_query->row['points_prefix'],
|
||||
'weight' => $option_value_query->row['weight'],
|
||||
'weight_prefix' => $option_value_query->row['weight_prefix']
|
||||
);
|
||||
}
|
||||
}
|
||||
} elseif ($option_query->row['type'] == 'text' || $option_query->row['type'] == 'textarea' || $option_query->row['type'] == 'file' || $option_query->row['type'] == 'date' || $option_query->row['type'] == 'datetime' || $option_query->row['type'] == 'time') {
|
||||
$option_data[] = array(
|
||||
'product_option_id' => $product_option_id,
|
||||
'product_option_value_id' => '',
|
||||
'option_id' => $option_query->row['option_id'],
|
||||
'option_value_id' => '',
|
||||
'name' => $option_query->row['name'],
|
||||
'value' => $value,
|
||||
'type' => $option_query->row['type'],
|
||||
'quantity' => '',
|
||||
'subtract' => '',
|
||||
'price' => '',
|
||||
'price_prefix' => '',
|
||||
'points' => '',
|
||||
'points_prefix' => '',
|
||||
'weight' => '',
|
||||
'weight_prefix' => ''
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$price = $product_query->row['price'];
|
||||
|
||||
// Product Discounts
|
||||
$discount_quantity = 0;
|
||||
|
||||
foreach ($cart_query->rows as $cart_2) {
|
||||
if ($cart_2['product_id'] == $cart['product_id']) {
|
||||
$discount_quantity += $cart_2['quantity'];
|
||||
}
|
||||
}
|
||||
|
||||
$product_discount_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND quantity <= '" . (int)$discount_quantity . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity DESC, priority ASC, price ASC LIMIT 1");
|
||||
|
||||
if ($product_discount_query->num_rows) {
|
||||
$price = $product_discount_query->row['price'];
|
||||
}
|
||||
|
||||
// Product Specials
|
||||
$product_special_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1");
|
||||
|
||||
if ($product_special_query->num_rows) {
|
||||
$price = $product_special_query->row['price'];
|
||||
}
|
||||
|
||||
// Reward Points
|
||||
$product_reward_query = $this->db->query("SELECT points FROM " . DB_PREFIX . "product_reward WHERE product_id = '" . (int)$cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "'");
|
||||
|
||||
if ($product_reward_query->num_rows) {
|
||||
$reward = $product_reward_query->row['points'];
|
||||
} else {
|
||||
$reward = 0;
|
||||
}
|
||||
|
||||
// Downloads
|
||||
$download_data = array();
|
||||
|
||||
$download_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_download p2d LEFT JOIN " . DB_PREFIX . "download d ON (p2d.download_id = d.download_id) LEFT JOIN " . DB_PREFIX . "download_description dd ON (d.download_id = dd.download_id) WHERE p2d.product_id = '" . (int)$cart['product_id'] . "' AND dd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($download_query->rows as $download) {
|
||||
$download_data[] = array(
|
||||
'download_id' => $download['download_id'],
|
||||
'name' => $download['name'],
|
||||
'filename' => $download['filename'],
|
||||
'mask' => $download['mask']
|
||||
);
|
||||
}
|
||||
|
||||
// Stock
|
||||
if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $cart['quantity'])) {
|
||||
$stock = false;
|
||||
}
|
||||
|
||||
$recurring_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "recurring r LEFT JOIN " . DB_PREFIX . "product_recurring pr ON (r.recurring_id = pr.recurring_id) LEFT JOIN " . DB_PREFIX . "recurring_description rd ON (r.recurring_id = rd.recurring_id) WHERE r.recurring_id = '" . (int)$cart['recurring_id'] . "' AND pr.product_id = '" . (int)$cart['product_id'] . "' AND rd.language_id = " . (int)$this->config->get('config_language_id') . " AND r.status = 1 AND pr.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "'");
|
||||
|
||||
if ($recurring_query->num_rows) {
|
||||
$recurring = array(
|
||||
'recurring_id' => $cart['recurring_id'],
|
||||
'name' => $recurring_query->row['name'],
|
||||
'frequency' => $recurring_query->row['frequency'],
|
||||
'price' => $recurring_query->row['price'],
|
||||
'cycle' => $recurring_query->row['cycle'],
|
||||
'duration' => $recurring_query->row['duration'],
|
||||
'trial' => $recurring_query->row['trial_status'],
|
||||
'trial_frequency' => $recurring_query->row['trial_frequency'],
|
||||
'trial_price' => $recurring_query->row['trial_price'],
|
||||
'trial_cycle' => $recurring_query->row['trial_cycle'],
|
||||
'trial_duration' => $recurring_query->row['trial_duration']
|
||||
);
|
||||
} else {
|
||||
$recurring = false;
|
||||
}
|
||||
|
||||
$product_data[] = array(
|
||||
'cart_id' => $cart['cart_id'],
|
||||
'product_id' => $product_query->row['product_id'],
|
||||
'name' => $product_query->row['name'],
|
||||
'model' => $product_query->row['model'],
|
||||
'shipping' => $product_query->row['shipping'],
|
||||
'image' => $product_query->row['image'],
|
||||
'option' => $option_data,
|
||||
'download' => $download_data,
|
||||
'quantity' => $cart['quantity'],
|
||||
'minimum' => $product_query->row['minimum'],
|
||||
'subtract' => $product_query->row['subtract'],
|
||||
'stock' => $stock,
|
||||
'price' => ($price + $option_price),
|
||||
'total' => ($price + $option_price) * $cart['quantity'],
|
||||
'reward' => $reward * $cart['quantity'],
|
||||
'points' => ($product_query->row['points'] ? ($product_query->row['points'] + $option_points) * $cart['quantity'] : 0),
|
||||
'tax_class_id' => $product_query->row['tax_class_id'],
|
||||
'weight' => ($product_query->row['weight'] + $option_weight) * $cart['quantity'],
|
||||
'weight_class_id' => $product_query->row['weight_class_id'],
|
||||
'length' => $product_query->row['length'],
|
||||
'width' => $product_query->row['width'],
|
||||
'height' => $product_query->row['height'],
|
||||
'length_class_id' => $product_query->row['length_class_id'],
|
||||
'recurring' => $recurring
|
||||
);
|
||||
} else {
|
||||
$this->remove($cart['cart_id']);
|
||||
}
|
||||
}
|
||||
|
||||
return $product_data;
|
||||
}
|
||||
|
||||
public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'");
|
||||
|
||||
if (!$query->row['total']) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "cart SET api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()");
|
||||
} else {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
public function update($cart_id, $quantity) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = '" . (int)$quantity . "' WHERE cart_id = '" . (int)$cart_id . "' AND api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");
|
||||
}
|
||||
|
||||
public function remove($cart_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE cart_id = '" . (int)$cart_id . "' AND api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");
|
||||
}
|
||||
|
||||
public function clear() {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");
|
||||
}
|
||||
|
||||
public function getRecurringProducts() {
|
||||
$product_data = array();
|
||||
|
||||
foreach ($this->getProducts() as $value) {
|
||||
if ($value['recurring']) {
|
||||
$product_data[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $product_data;
|
||||
}
|
||||
|
||||
public function getWeight() {
|
||||
$weight = 0;
|
||||
|
||||
foreach ($this->getProducts() as $product) {
|
||||
if ($product['shipping']) {
|
||||
$weight += $this->weight->convert($product['weight'], $product['weight_class_id'], $this->config->get('config_weight_class_id'));
|
||||
}
|
||||
}
|
||||
|
||||
return $weight;
|
||||
}
|
||||
|
||||
public function getSubTotal() {
|
||||
$total = 0;
|
||||
|
||||
foreach ($this->getProducts() as $product) {
|
||||
$total += $product['total'];
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function getTaxes() {
|
||||
$tax_data = array();
|
||||
|
||||
foreach ($this->getProducts() as $product) {
|
||||
if ($product['tax_class_id']) {
|
||||
$tax_rates = $this->tax->getRates($product['price'], $product['tax_class_id']);
|
||||
|
||||
foreach ($tax_rates as $tax_rate) {
|
||||
if (!isset($tax_data[$tax_rate['tax_rate_id']])) {
|
||||
$tax_data[$tax_rate['tax_rate_id']] = ($tax_rate['amount'] * $product['quantity']);
|
||||
} else {
|
||||
$tax_data[$tax_rate['tax_rate_id']] += ($tax_rate['amount'] * $product['quantity']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $tax_data;
|
||||
}
|
||||
|
||||
public function getTotal() {
|
||||
$total = 0;
|
||||
|
||||
foreach ($this->getProducts() as $product) {
|
||||
$total += $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity'];
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
public function countProducts() {
|
||||
$product_total = 0;
|
||||
|
||||
$products = $this->getProducts();
|
||||
|
||||
foreach ($products as $product) {
|
||||
$product_total += $product['quantity'];
|
||||
}
|
||||
|
||||
return $product_total;
|
||||
}
|
||||
|
||||
public function hasProducts() {
|
||||
return count($this->getProducts());
|
||||
}
|
||||
|
||||
public function hasRecurringProducts() {
|
||||
return count($this->getRecurringProducts());
|
||||
}
|
||||
|
||||
public function hasStock() {
|
||||
foreach ($this->getProducts() as $product) {
|
||||
if (!$product['stock']) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hasShipping() {
|
||||
foreach ($this->getProducts() as $product) {
|
||||
if ($product['shipping']) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hasDownload() {
|
||||
foreach ($this->getProducts() as $product) {
|
||||
if ($product['download']) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
namespace Cart;
|
||||
class Currency {
|
||||
private $currencies = array();
|
||||
|
||||
public function __construct($registry) {
|
||||
$this->db = $registry->get('db');
|
||||
$this->language = $registry->get('language');
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$this->currencies[$result['code']] = array(
|
||||
'currency_id' => $result['currency_id'],
|
||||
'title' => $result['title'],
|
||||
'symbol_left' => $result['symbol_left'],
|
||||
'symbol_right' => $result['symbol_right'],
|
||||
'decimal_place' => $result['decimal_place'],
|
||||
'value' => $result['value']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function format($number, $currency, $value = '', $format = true) {
|
||||
$symbol_left = $this->currencies[$currency]['symbol_left'];
|
||||
$symbol_right = $this->currencies[$currency]['symbol_right'];
|
||||
$decimal_place = $this->currencies[$currency]['decimal_place'];
|
||||
|
||||
if (!$value) {
|
||||
$value = $this->currencies[$currency]['value'];
|
||||
}
|
||||
|
||||
$amount = $value ? (float)$number * $value : (float)$number;
|
||||
|
||||
$amount = round($amount, (int)$decimal_place);
|
||||
|
||||
if (!$format) {
|
||||
return $amount;
|
||||
}
|
||||
|
||||
$string = '';
|
||||
|
||||
if ($symbol_left) {
|
||||
$string .= $symbol_left;
|
||||
}
|
||||
|
||||
$string .= number_format($amount, (int)$decimal_place, $this->language->get('decimal_point'), $this->language->get('thousand_point'));
|
||||
|
||||
if ($symbol_right) {
|
||||
$string .= $symbol_right;
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public function convert($value, $from, $to) {
|
||||
if (isset($this->currencies[$from])) {
|
||||
$from = $this->currencies[$from]['value'];
|
||||
} else {
|
||||
$from = 1;
|
||||
}
|
||||
|
||||
if (isset($this->currencies[$to])) {
|
||||
$to = $this->currencies[$to]['value'];
|
||||
} else {
|
||||
$to = 1;
|
||||
}
|
||||
|
||||
return $value * ($to / $from);
|
||||
}
|
||||
|
||||
public function getId($currency) {
|
||||
if (isset($this->currencies[$currency])) {
|
||||
return $this->currencies[$currency]['currency_id'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSymbolLeft($currency) {
|
||||
if (isset($this->currencies[$currency])) {
|
||||
return $this->currencies[$currency]['symbol_left'];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
public function getSymbolRight($currency) {
|
||||
if (isset($this->currencies[$currency])) {
|
||||
return $this->currencies[$currency]['symbol_right'];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
public function getDecimalPlace($currency) {
|
||||
if (isset($this->currencies[$currency])) {
|
||||
return $this->currencies[$currency]['decimal_place'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getValue($currency) {
|
||||
if (isset($this->currencies[$currency])) {
|
||||
return $this->currencies[$currency]['value'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function has($currency) {
|
||||
return isset($this->currencies[$currency]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Cart;
|
||||
class Customer {
|
||||
private $customer_id;
|
||||
private $firstname;
|
||||
private $lastname;
|
||||
private $customer_group_id;
|
||||
private $email;
|
||||
private $telephone;
|
||||
private $newsletter;
|
||||
private $address_id;
|
||||
|
||||
public function __construct($registry) {
|
||||
$this->config = $registry->get('config');
|
||||
$this->db = $registry->get('db');
|
||||
$this->request = $registry->get('request');
|
||||
$this->session = $registry->get('session');
|
||||
|
||||
if (isset($this->session->data['customer_id'])) {
|
||||
$customer_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$this->session->data['customer_id'] . "' AND status = '1'");
|
||||
|
||||
if ($customer_query->num_rows) {
|
||||
$this->customer_id = $customer_query->row['customer_id'];
|
||||
$this->firstname = $customer_query->row['firstname'];
|
||||
$this->lastname = $customer_query->row['lastname'];
|
||||
$this->customer_group_id = $customer_query->row['customer_group_id'];
|
||||
$this->email = $customer_query->row['email'];
|
||||
$this->telephone = $customer_query->row['telephone'];
|
||||
$this->newsletter = $customer_query->row['newsletter'];
|
||||
$this->address_id = $customer_query->row['address_id'];
|
||||
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "customer SET language_id = '" . (int)$this->config->get('config_language_id') . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "' WHERE customer_id = '" . (int)$this->customer_id . "'");
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer_ip WHERE customer_id = '" . (int)$this->session->data['customer_id'] . "' AND ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "'");
|
||||
|
||||
if (!$query->num_rows) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "customer_ip SET customer_id = '" . (int)$this->session->data['customer_id'] . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "', date_added = NOW()");
|
||||
}
|
||||
} else {
|
||||
$this->logout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function login($email, $password, $override = false) {
|
||||
if ($override) {
|
||||
$customer_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "' AND status = '1'");
|
||||
} else {
|
||||
$customer_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "' AND (password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1('" . $this->db->escape($password) . "'))))) OR password = '" . $this->db->escape(md5($password)) . "') AND status = '1'");
|
||||
}
|
||||
|
||||
if ($customer_query->num_rows) {
|
||||
$this->session->data['customer_id'] = $customer_query->row['customer_id'];
|
||||
|
||||
$this->customer_id = $customer_query->row['customer_id'];
|
||||
$this->firstname = $customer_query->row['firstname'];
|
||||
$this->lastname = $customer_query->row['lastname'];
|
||||
$this->customer_group_id = $customer_query->row['customer_group_id'];
|
||||
$this->email = $customer_query->row['email'];
|
||||
$this->telephone = $customer_query->row['telephone'];
|
||||
$this->newsletter = $customer_query->row['newsletter'];
|
||||
$this->address_id = $customer_query->row['address_id'];
|
||||
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "customer SET language_id = '" . (int)$this->config->get('config_language_id') . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "' WHERE customer_id = '" . (int)$this->customer_id . "'");
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
unset($this->session->data['customer_id']);
|
||||
|
||||
$this->customer_id = '';
|
||||
$this->firstname = '';
|
||||
$this->lastname = '';
|
||||
$this->customer_group_id = '';
|
||||
$this->email = '';
|
||||
$this->telephone = '';
|
||||
$this->newsletter = '';
|
||||
$this->address_id = '';
|
||||
}
|
||||
|
||||
public function isLogged() {
|
||||
return $this->customer_id;
|
||||
}
|
||||
|
||||
public function getId() {
|
||||
return $this->customer_id;
|
||||
}
|
||||
|
||||
public function getFirstName() {
|
||||
return $this->firstname;
|
||||
}
|
||||
|
||||
public function getLastName() {
|
||||
return $this->lastname;
|
||||
}
|
||||
|
||||
public function getGroupId() {
|
||||
return $this->customer_group_id;
|
||||
}
|
||||
|
||||
public function getEmail() {
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function getTelephone() {
|
||||
return $this->telephone;
|
||||
}
|
||||
|
||||
public function getNewsletter() {
|
||||
return $this->newsletter;
|
||||
}
|
||||
|
||||
public function getAddressId() {
|
||||
return $this->address_id;
|
||||
}
|
||||
|
||||
public function getBalance() {
|
||||
$query = $this->db->query("SELECT SUM(amount) AS total FROM " . DB_PREFIX . "customer_transaction WHERE customer_id = '" . (int)$this->customer_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getRewardPoints() {
|
||||
$query = $this->db->query("SELECT SUM(points) AS total FROM " . DB_PREFIX . "customer_reward WHERE customer_id = '" . (int)$this->customer_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
namespace Cart;
|
||||
class Length {
|
||||
private $lengths = array();
|
||||
|
||||
public function __construct($registry) {
|
||||
$this->db = $registry->get('db');
|
||||
$this->config = $registry->get('config');
|
||||
|
||||
$length_class_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "length_class mc LEFT JOIN " . DB_PREFIX . "length_class_description mcd ON (mc.length_class_id = mcd.length_class_id) WHERE mcd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($length_class_query->rows as $result) {
|
||||
$this->lengths[$result['length_class_id']] = array(
|
||||
'length_class_id' => $result['length_class_id'],
|
||||
'title' => $result['title'],
|
||||
'unit' => $result['unit'],
|
||||
'value' => $result['value']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function convert($value, $from, $to) {
|
||||
if ($from == $to) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (isset($this->lengths[$from])) {
|
||||
$from = $this->lengths[$from]['value'];
|
||||
} else {
|
||||
$from = 1;
|
||||
}
|
||||
|
||||
if (isset($this->lengths[$to])) {
|
||||
$to = $this->lengths[$to]['value'];
|
||||
} else {
|
||||
$to = 1;
|
||||
}
|
||||
|
||||
return $value * ($to / $from);
|
||||
}
|
||||
|
||||
public function format($value, $length_class_id, $decimal_point = '.', $thousand_point = ',') {
|
||||
if (isset($this->lengths[$length_class_id])) {
|
||||
return number_format($value, 2, $decimal_point, $thousand_point) . $this->lengths[$length_class_id]['unit'];
|
||||
} else {
|
||||
return number_format($value, 2, $decimal_point, $thousand_point);
|
||||
}
|
||||
}
|
||||
|
||||
public function getUnit($length_class_id) {
|
||||
if (isset($this->lengths[$length_class_id])) {
|
||||
return $this->lengths[$length_class_id]['unit'];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
namespace Cart;
|
||||
final class Tax {
|
||||
private $tax_rates = array();
|
||||
|
||||
public function __construct($registry) {
|
||||
$this->config = $registry->get('config');
|
||||
$this->db = $registry->get('db');
|
||||
}
|
||||
|
||||
public function unsetRates() {
|
||||
$this->tax_rates = array();
|
||||
}
|
||||
|
||||
public function setShippingAddress($country_id, $zone_id) {
|
||||
$tax_query = $this->db->query("SELECT tr1.tax_class_id, tr2.tax_rate_id, tr2.name, tr2.rate, tr2.type, tr1.priority FROM " . DB_PREFIX . "tax_rule tr1 LEFT JOIN " . DB_PREFIX . "tax_rate tr2 ON (tr1.tax_rate_id = tr2.tax_rate_id) INNER JOIN " . DB_PREFIX . "tax_rate_to_customer_group tr2cg ON (tr2.tax_rate_id = tr2cg.tax_rate_id) LEFT JOIN " . DB_PREFIX . "zone_to_geo_zone z2gz ON (tr2.geo_zone_id = z2gz.geo_zone_id) LEFT JOIN " . DB_PREFIX . "geo_zone gz ON (tr2.geo_zone_id = gz.geo_zone_id) WHERE tr1.based = 'shipping' AND tr2cg.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND z2gz.country_id = '" . (int)$country_id . "' AND (z2gz.zone_id = '0' OR z2gz.zone_id = '" . (int)$zone_id . "') ORDER BY tr1.priority ASC");
|
||||
|
||||
foreach ($tax_query->rows as $result) {
|
||||
$this->tax_rates[$result['tax_class_id']][$result['tax_rate_id']] = array(
|
||||
'tax_rate_id' => $result['tax_rate_id'],
|
||||
'name' => $result['name'],
|
||||
'rate' => $result['rate'],
|
||||
'type' => $result['type'],
|
||||
'priority' => $result['priority']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function setPaymentAddress($country_id, $zone_id) {
|
||||
$tax_query = $this->db->query("SELECT tr1.tax_class_id, tr2.tax_rate_id, tr2.name, tr2.rate, tr2.type, tr1.priority FROM " . DB_PREFIX . "tax_rule tr1 LEFT JOIN " . DB_PREFIX . "tax_rate tr2 ON (tr1.tax_rate_id = tr2.tax_rate_id) INNER JOIN " . DB_PREFIX . "tax_rate_to_customer_group tr2cg ON (tr2.tax_rate_id = tr2cg.tax_rate_id) LEFT JOIN " . DB_PREFIX . "zone_to_geo_zone z2gz ON (tr2.geo_zone_id = z2gz.geo_zone_id) LEFT JOIN " . DB_PREFIX . "geo_zone gz ON (tr2.geo_zone_id = gz.geo_zone_id) WHERE tr1.based = 'payment' AND tr2cg.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND z2gz.country_id = '" . (int)$country_id . "' AND (z2gz.zone_id = '0' OR z2gz.zone_id = '" . (int)$zone_id . "') ORDER BY tr1.priority ASC");
|
||||
|
||||
foreach ($tax_query->rows as $result) {
|
||||
$this->tax_rates[$result['tax_class_id']][$result['tax_rate_id']] = array(
|
||||
'tax_rate_id' => $result['tax_rate_id'],
|
||||
'name' => $result['name'],
|
||||
'rate' => $result['rate'],
|
||||
'type' => $result['type'],
|
||||
'priority' => $result['priority']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function setStoreAddress($country_id, $zone_id) {
|
||||
$tax_query = $this->db->query("SELECT tr1.tax_class_id, tr2.tax_rate_id, tr2.name, tr2.rate, tr2.type, tr1.priority FROM " . DB_PREFIX . "tax_rule tr1 LEFT JOIN " . DB_PREFIX . "tax_rate tr2 ON (tr1.tax_rate_id = tr2.tax_rate_id) INNER JOIN " . DB_PREFIX . "tax_rate_to_customer_group tr2cg ON (tr2.tax_rate_id = tr2cg.tax_rate_id) LEFT JOIN " . DB_PREFIX . "zone_to_geo_zone z2gz ON (tr2.geo_zone_id = z2gz.geo_zone_id) LEFT JOIN " . DB_PREFIX . "geo_zone gz ON (tr2.geo_zone_id = gz.geo_zone_id) WHERE tr1.based = 'store' AND tr2cg.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND z2gz.country_id = '" . (int)$country_id . "' AND (z2gz.zone_id = '0' OR z2gz.zone_id = '" . (int)$zone_id . "') ORDER BY tr1.priority ASC");
|
||||
|
||||
foreach ($tax_query->rows as $result) {
|
||||
$this->tax_rates[$result['tax_class_id']][$result['tax_rate_id']] = array(
|
||||
'tax_rate_id' => $result['tax_rate_id'],
|
||||
'name' => $result['name'],
|
||||
'rate' => $result['rate'],
|
||||
'type' => $result['type'],
|
||||
'priority' => $result['priority']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function calculate($value, $tax_class_id, $calculate = true) {
|
||||
if ($tax_class_id && $calculate) {
|
||||
$amount = 0;
|
||||
|
||||
$tax_rates = $this->getRates($value, $tax_class_id);
|
||||
|
||||
foreach ($tax_rates as $tax_rate) {
|
||||
if ($calculate != 'P' && $calculate != 'F') {
|
||||
$amount += $tax_rate['amount'];
|
||||
} elseif ($tax_rate['type'] == $calculate) {
|
||||
$amount += $tax_rate['amount'];
|
||||
}
|
||||
}
|
||||
|
||||
return $value + $amount;
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTax($value, $tax_class_id) {
|
||||
$amount = 0;
|
||||
|
||||
$tax_rates = $this->getRates($value, $tax_class_id);
|
||||
|
||||
foreach ($tax_rates as $tax_rate) {
|
||||
$amount += $tax_rate['amount'];
|
||||
}
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
public function getRateName($tax_rate_id) {
|
||||
$tax_query = $this->db->query("SELECT name FROM " . DB_PREFIX . "tax_rate WHERE tax_rate_id = '" . (int)$tax_rate_id . "'");
|
||||
|
||||
if ($tax_query->num_rows) {
|
||||
return $tax_query->row['name'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getRates($value, $tax_class_id) {
|
||||
$tax_rate_data = array();
|
||||
|
||||
if (isset($this->tax_rates[$tax_class_id])) {
|
||||
foreach ($this->tax_rates[$tax_class_id] as $tax_rate) {
|
||||
if (isset($tax_rate_data[$tax_rate['tax_rate_id']])) {
|
||||
$amount = $tax_rate_data[$tax_rate['tax_rate_id']]['amount'];
|
||||
} else {
|
||||
$amount = 0;
|
||||
}
|
||||
|
||||
if ($tax_rate['type'] == 'F') {
|
||||
$amount += $tax_rate['rate'];
|
||||
} elseif ($tax_rate['type'] == 'P') {
|
||||
$amount += ($value / 100 * $tax_rate['rate']);
|
||||
}
|
||||
|
||||
$tax_rate_data[$tax_rate['tax_rate_id']] = array(
|
||||
'tax_rate_id' => $tax_rate['tax_rate_id'],
|
||||
'name' => $tax_rate['name'],
|
||||
'rate' => $tax_rate['rate'],
|
||||
'type' => $tax_rate['type'],
|
||||
'amount' => $amount
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $tax_rate_data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
namespace Cart;
|
||||
class User {
|
||||
private $user_id;
|
||||
private $user_group_id;
|
||||
private $username;
|
||||
private $permission = array();
|
||||
|
||||
public function __construct($registry) {
|
||||
$this->db = $registry->get('db');
|
||||
$this->request = $registry->get('request');
|
||||
$this->session = $registry->get('session');
|
||||
|
||||
if (isset($this->session->data['user_id'])) {
|
||||
$user_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "user WHERE user_id = '" . (int)$this->session->data['user_id'] . "' AND status = '1'");
|
||||
|
||||
if ($user_query->num_rows) {
|
||||
$this->user_id = $user_query->row['user_id'];
|
||||
$this->username = $user_query->row['username'];
|
||||
$this->user_group_id = $user_query->row['user_group_id'];
|
||||
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "user SET ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "' WHERE user_id = '" . (int)$this->session->data['user_id'] . "'");
|
||||
|
||||
$user_group_query = $this->db->query("SELECT permission FROM " . DB_PREFIX . "user_group WHERE user_group_id = '" . (int)$user_query->row['user_group_id'] . "'");
|
||||
|
||||
$permissions = json_decode($user_group_query->row['permission'], true);
|
||||
|
||||
if (is_array($permissions)) {
|
||||
foreach ($permissions as $key => $value) {
|
||||
$this->permission[$key] = $value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->logout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function login($username, $password) {
|
||||
$user_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "user WHERE username = '" . $this->db->escape($username) . "' AND (password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1('" . $this->db->escape($password) . "'))))) OR password = '" . $this->db->escape(md5($password)) . "') AND status = '1'");
|
||||
|
||||
if ($user_query->num_rows) {
|
||||
$this->session->data['user_id'] = $user_query->row['user_id'];
|
||||
|
||||
$this->user_id = $user_query->row['user_id'];
|
||||
$this->username = $user_query->row['username'];
|
||||
$this->user_group_id = $user_query->row['user_group_id'];
|
||||
|
||||
$user_group_query = $this->db->query("SELECT permission FROM " . DB_PREFIX . "user_group WHERE user_group_id = '" . (int)$user_query->row['user_group_id'] . "'");
|
||||
|
||||
$permissions = json_decode($user_group_query->row['permission'], true);
|
||||
|
||||
if (is_array($permissions)) {
|
||||
foreach ($permissions as $key => $value) {
|
||||
$this->permission[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
unset($this->session->data['user_id']);
|
||||
|
||||
$this->user_id = '';
|
||||
$this->username = '';
|
||||
}
|
||||
|
||||
public function hasPermission($key, $value) {
|
||||
if (isset($this->permission[$key])) {
|
||||
return in_array($value, $this->permission[$key]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function isLogged() {
|
||||
return $this->user_id;
|
||||
}
|
||||
|
||||
public function getId() {
|
||||
return $this->user_id;
|
||||
}
|
||||
|
||||
public function getUserName() {
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function getGroupId() {
|
||||
return $this->user_group_id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
namespace Cart;
|
||||
class Weight {
|
||||
private $weights = array();
|
||||
|
||||
public function __construct($registry) {
|
||||
$this->db = $registry->get('db');
|
||||
$this->config = $registry->get('config');
|
||||
|
||||
$weight_class_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "weight_class wc LEFT JOIN " . DB_PREFIX . "weight_class_description wcd ON (wc.weight_class_id = wcd.weight_class_id) WHERE wcd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($weight_class_query->rows as $result) {
|
||||
$this->weights[$result['weight_class_id']] = array(
|
||||
'weight_class_id' => $result['weight_class_id'],
|
||||
'title' => $result['title'],
|
||||
'unit' => $result['unit'],
|
||||
'value' => $result['value']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function convert($value, $from, $to) {
|
||||
if ($from == $to) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (isset($this->weights[$from])) {
|
||||
$from = $this->weights[$from]['value'];
|
||||
} else {
|
||||
$from = 1;
|
||||
}
|
||||
|
||||
if (isset($this->weights[$to])) {
|
||||
$to = $this->weights[$to]['value'];
|
||||
} else {
|
||||
$to = 1;
|
||||
}
|
||||
|
||||
return $value * ($to / $from);
|
||||
}
|
||||
|
||||
public function format($value, $weight_class_id, $decimal_point = '.', $thousand_point = ',') {
|
||||
if (isset($this->weights[$weight_class_id])) {
|
||||
return number_format($value, 2, $decimal_point, $thousand_point) . $this->weights[$weight_class_id]['unit'];
|
||||
} else {
|
||||
return number_format($value, 2, $decimal_point, $thousand_point);
|
||||
}
|
||||
}
|
||||
|
||||
public function getUnit($weight_class_id) {
|
||||
if (isset($this->weights[$weight_class_id])) {
|
||||
return $this->weights[$weight_class_id]['unit'];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* Config class
|
||||
*/
|
||||
class Config {
|
||||
private $data = array();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key) {
|
||||
return (isset($this->data[$key]) ? $this->data[$key] : null);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
public function set($key, $value) {
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function has($key) {
|
||||
return isset($this->data[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $filename
|
||||
*/
|
||||
public function load($filename) {
|
||||
$file = DIR_CONFIG . $filename . '.php';
|
||||
|
||||
if (file_exists($file)) {
|
||||
$_ = array();
|
||||
|
||||
require(modification($file));
|
||||
|
||||
$this->data = array_merge($this->data, $_);
|
||||
} else {
|
||||
trigger_error('Error: Could not load config ' . $filename . '!');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* DB class
|
||||
*/
|
||||
class DB {
|
||||
private $adaptor;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $adaptor
|
||||
* @param string $hostname
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param string $database
|
||||
* @param int $port
|
||||
*
|
||||
*/
|
||||
public function __construct($adaptor, $hostname, $username, $password, $database, $port = NULL) {
|
||||
$class = 'DB\\' . $adaptor;
|
||||
|
||||
if (class_exists($class)) {
|
||||
$this->adaptor = new $class($hostname, $username, $password, $database, $port);
|
||||
} else {
|
||||
throw new \Exception('Error: Could not load database adaptor ' . $adaptor . '!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $sql
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function query($sql) {
|
||||
return $this->adaptor->query($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function escape($value) {
|
||||
return $this->adaptor->escape($value);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countAffected() {
|
||||
return $this->adaptor->countAffected();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLastId() {
|
||||
return $this->adaptor->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function connected() {
|
||||
return $this->adaptor->connected();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
namespace DB;
|
||||
final class mPDO {
|
||||
private $connection = null;
|
||||
private $statement = null;
|
||||
|
||||
public function __construct($hostname, $username, $password, $database, $port = '3306') {
|
||||
try {
|
||||
$this->connection = new \PDO("mysql:host=" . $hostname . ";port=" . $port . ";dbname=" . $database, $username, $password, array(\PDO::ATTR_PERSISTENT => true));
|
||||
} catch(\PDOException $e) {
|
||||
throw new \Exception('Failed to connect to database. Reason: \'' . $e->getMessage() . '\'');
|
||||
}
|
||||
|
||||
$this->connection->exec("SET NAMES 'utf8'");
|
||||
$this->connection->exec("SET CHARACTER SET utf8");
|
||||
$this->connection->exec("SET CHARACTER_SET_CONNECTION=utf8");
|
||||
$this->connection->exec("SET SQL_MODE = ''");
|
||||
}
|
||||
|
||||
public function prepare($sql) {
|
||||
$this->statement = $this->connection->prepare($sql);
|
||||
}
|
||||
|
||||
public function bindParam($parameter, $variable, $data_type = \PDO::PARAM_STR, $length = 0) {
|
||||
if ($length) {
|
||||
$this->statement->bindParam($parameter, $variable, $data_type, $length);
|
||||
} else {
|
||||
$this->statement->bindParam($parameter, $variable, $data_type);
|
||||
}
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
try {
|
||||
if ($this->statement && $this->statement->execute()) {
|
||||
$data = array();
|
||||
|
||||
while ($row = $this->statement->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
$result = new \stdClass();
|
||||
$result->row = (isset($data[0])) ? $data[0] : array();
|
||||
$result->rows = $data;
|
||||
$result->num_rows = $this->statement->rowCount();
|
||||
}
|
||||
} catch(\PDOException $e) {
|
||||
throw new \Exception('Error: ' . $e->getMessage() . ' Error Code : ' . $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function query($sql, $params = array()) {
|
||||
$this->statement = $this->connection->prepare($sql);
|
||||
|
||||
$result = false;
|
||||
|
||||
try {
|
||||
if ($this->statement && $this->statement->execute($params)) {
|
||||
$data = array();
|
||||
|
||||
while ($row = $this->statement->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
$result = new \stdClass();
|
||||
$result->row = (isset($data[0]) ? $data[0] : array());
|
||||
$result->rows = $data;
|
||||
$result->num_rows = $this->statement->rowCount();
|
||||
}
|
||||
} catch (\PDOException $e) {
|
||||
throw new \Exception('Error: ' . $e->getMessage() . ' Error Code : ' . $e->getCode() . ' <br />' . $sql);
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
return $result;
|
||||
} else {
|
||||
$result = new \stdClass();
|
||||
$result->row = array();
|
||||
$result->rows = array();
|
||||
$result->num_rows = 0;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
public function escape($value) {
|
||||
return str_replace(array("\\", "\0", "\n", "\r", "\x1a", "'", '"'), array("\\\\", "\\0", "\\n", "\\r", "\Z", "\'", '\"'), $value);
|
||||
}
|
||||
|
||||
public function countAffected() {
|
||||
if ($this->statement) {
|
||||
return $this->statement->rowCount();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function getLastId() {
|
||||
return $this->connection->lastInsertId();
|
||||
}
|
||||
|
||||
public function isConnected() {
|
||||
if ($this->connection) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
$this->connection = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace DB;
|
||||
final class MSSQL {
|
||||
private $connection;
|
||||
|
||||
public function __construct($hostname, $username, $password, $database, $port = '1433') {
|
||||
if (!$this->connection = mssql_connect($hostname. ':' . $port, $username, $password)) {
|
||||
throw new \Exception('Error: Could not make a database connection using ' . $username . '@' . $hostname);
|
||||
}
|
||||
|
||||
if (!mssql_select_db($database, $this->link)) {
|
||||
throw new \Exception('Error: Could not connect to database ' . $database);
|
||||
}
|
||||
|
||||
mssql_query("SET NAMES 'utf8'", $this->connection);
|
||||
mssql_query("SET CHARACTER SET utf8", $this->connection);
|
||||
}
|
||||
|
||||
public function query($sql) {
|
||||
$resource = mssql_query($sql, $this->connection);
|
||||
|
||||
if ($resource) {
|
||||
if (is_resource($resource)) {
|
||||
$i = 0;
|
||||
|
||||
$data = array();
|
||||
|
||||
while ($result = mssql_fetch_assoc($resource)) {
|
||||
$data[$i] = $result;
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
mssql_free_result($resource);
|
||||
|
||||
$query = new \stdClass();
|
||||
$query->row = isset($data[0]) ? $data[0] : array();
|
||||
$query->rows = $data;
|
||||
$query->num_rows = $i;
|
||||
|
||||
unset($data);
|
||||
|
||||
return $query;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
throw new \Exception('Error: ' . mssql_get_last_message($this->connection) . '<br />' . $sql);
|
||||
}
|
||||
}
|
||||
|
||||
public function escape($value) {
|
||||
$unpacked = unpack('H*hex', $value);
|
||||
|
||||
return '0x' . $unpacked['hex'];
|
||||
}
|
||||
|
||||
public function countAffected() {
|
||||
return mssql_rows_affected($this->connection);
|
||||
}
|
||||
|
||||
public function getLastId() {
|
||||
$last_id = false;
|
||||
|
||||
$resource = mssql_query("SELECT @@identity AS id", $this->connection);
|
||||
|
||||
if ($row = mssql_fetch_row($resource)) {
|
||||
$last_id = trim($row[0]);
|
||||
}
|
||||
|
||||
mssql_free_result($resource);
|
||||
|
||||
return $last_id;
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
mssql_close($this->connection);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
namespace DB;
|
||||
final class MySQL {
|
||||
private $connection;
|
||||
|
||||
public function __construct($hostname, $username, $password, $database, $port = '3306') {
|
||||
if (!$this->connection = mysql_connect($hostname . ':' . $port, $username, $password)) {
|
||||
trigger_error('Error: Could not make a database link using ' . $username . '@' . $hostname);
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!mysql_select_db($database, $this->connection)) {
|
||||
throw new \Exception('Error: Could not connect to database ' . $database);
|
||||
}
|
||||
|
||||
mysql_query("SET NAMES 'utf8'", $this->connection);
|
||||
mysql_query("SET CHARACTER SET utf8", $this->connection);
|
||||
mysql_query("SET CHARACTER_SET_CONNECTION=utf8", $this->connection);
|
||||
mysql_query("SET SQL_MODE = ''", $this->connection);
|
||||
}
|
||||
|
||||
public function query($sql) {
|
||||
if ($this->connection) {
|
||||
$resource = mysql_query($sql, $this->connection);
|
||||
|
||||
if ($resource) {
|
||||
if (is_resource($resource)) {
|
||||
$i = 0;
|
||||
|
||||
$data = array();
|
||||
|
||||
while ($result = mysql_fetch_assoc($resource)) {
|
||||
$data[$i] = $result;
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
mysql_free_result($resource);
|
||||
|
||||
$query = new \stdClass();
|
||||
$query->row = isset($data[0]) ? $data[0] : array();
|
||||
$query->rows = $data;
|
||||
$query->num_rows = $i;
|
||||
|
||||
unset($data);
|
||||
|
||||
return $query;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
$trace = debug_backtrace();
|
||||
|
||||
throw new \Exception('Error: ' . mysql_error($this->connection) . '<br />Error No: ' . mysql_errno($this->connection) . '<br /> Error in: <b>' . $trace[1]['file'] . '</b> line <b>' . $trace[1]['line'] . '</b><br />' . $sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function escape($value) {
|
||||
if ($this->connection) {
|
||||
return mysql_real_escape_string($value, $this->connection);
|
||||
}
|
||||
}
|
||||
|
||||
public function countAffected() {
|
||||
if ($this->connection) {
|
||||
return mysql_affected_rows($this->connection);
|
||||
}
|
||||
}
|
||||
|
||||
public function getLastId() {
|
||||
if ($this->connection) {
|
||||
return mysql_insert_id($this->connection);
|
||||
}
|
||||
}
|
||||
|
||||
public function isConnected() {
|
||||
if ($this->connection) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
if ($this->connection) {
|
||||
mysql_close($this->connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace DB;
|
||||
final class MySQLi {
|
||||
private $connection;
|
||||
|
||||
public function __construct($hostname, $username, $password, $database, $port = '3306') {
|
||||
$this->connection = new \mysqli($hostname, $username, $password, $database, $port);
|
||||
|
||||
if ($this->connection->connect_error) {
|
||||
throw new \Exception('Error: ' . $this->connection->connect_error . '<br />Error No: ' . $this->connection->connect_errno);
|
||||
}
|
||||
|
||||
$this->connection->set_charset("utf8");
|
||||
$this->connection->query("SET SQL_MODE = ''");
|
||||
$this->connection->query("SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'");
|
||||
}
|
||||
|
||||
public function query($sql) {
|
||||
$query = $this->connection->query($sql);
|
||||
|
||||
if (!$this->connection->errno) {
|
||||
if ($query instanceof \mysqli_result) {
|
||||
$data = array();
|
||||
|
||||
while ($row = $query->fetch_assoc()) {
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
$result = new \stdClass();
|
||||
$result->num_rows = $query->num_rows;
|
||||
$result->row = isset($data[0]) ? $data[0] : array();
|
||||
$result->rows = $data;
|
||||
|
||||
$query->close();
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
throw new \Exception('Error: ' . $this->connection->error . '<br />Error No: ' . $this->connection->errno . '<br />' . $sql);
|
||||
}
|
||||
}
|
||||
|
||||
public function escape($value) {
|
||||
return $this->connection->real_escape_string($value);
|
||||
}
|
||||
|
||||
public function countAffected() {
|
||||
return $this->connection->affected_rows;
|
||||
}
|
||||
|
||||
public function getLastId() {
|
||||
return $this->connection->insert_id;
|
||||
}
|
||||
|
||||
public function connected() {
|
||||
return $this->connection->ping();
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
$this->connection->close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
namespace DB;
|
||||
final class PgSQL {
|
||||
private $link;
|
||||
|
||||
public function __construct($hostname, $username, $password, $database, $port = '5432') {
|
||||
if (!$this->link = pg_connect('hostname=' . $hostname . ' port=' . $port . ' username=' . $username . ' password=' . $password . ' database=' . $database)) {
|
||||
throw new \Exception('Error: Could not make a database link using ' . $username . '@' . $hostname);
|
||||
}
|
||||
|
||||
if (!mysql_select_db($database, $this->link)) {
|
||||
throw new \Exception('Error: Could not connect to database ' . $database);
|
||||
}
|
||||
|
||||
pg_query($this->link, "SET CLIENT_ENCODING TO 'UTF8'");
|
||||
}
|
||||
|
||||
public function query($sql) {
|
||||
$resource = pg_query($this->link, $sql);
|
||||
|
||||
if ($resource) {
|
||||
if (is_resource($resource)) {
|
||||
$i = 0;
|
||||
|
||||
$data = array();
|
||||
|
||||
while ($result = pg_fetch_assoc($resource)) {
|
||||
$data[$i] = $result;
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
pg_free_result($resource);
|
||||
|
||||
$query = new \stdClass();
|
||||
$query->row = isset($data[0]) ? $data[0] : array();
|
||||
$query->rows = $data;
|
||||
$query->num_rows = $i;
|
||||
|
||||
unset($data);
|
||||
|
||||
return $query;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
throw new \Exception('Error: ' . pg_result_error($this->link) . '<br />' . $sql);
|
||||
}
|
||||
}
|
||||
|
||||
public function escape($value) {
|
||||
return pg_escape_string($this->link, $value);
|
||||
}
|
||||
|
||||
public function countAffected() {
|
||||
return pg_affected_rows($this->link);
|
||||
}
|
||||
|
||||
public function getLastId() {
|
||||
$query = $this->query("SELECT LASTVAL() AS `id`");
|
||||
|
||||
return $query->row['id'];
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
pg_close($this->link);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* Document class
|
||||
*/
|
||||
class Document {
|
||||
private $title;
|
||||
private $robots;
|
||||
private $description;
|
||||
private $keywords;
|
||||
|
||||
private $links = array();
|
||||
private $styles = array();
|
||||
private $scripts = array();
|
||||
private $og_image;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setRobots($robots) {
|
||||
$this->robots = $robots;
|
||||
}
|
||||
|
||||
public function getRobots() {
|
||||
return $this->robots;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $description
|
||||
*/
|
||||
public function setDescription($description) {
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $keywords
|
||||
*/
|
||||
public function setKeywords($keywords) {
|
||||
$this->keywords = $keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getKeywords() {
|
||||
return $this->keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $href
|
||||
* @param string $rel
|
||||
*/
|
||||
public function addLink($href, $rel) {
|
||||
$this->links[$href] = array(
|
||||
'href' => $href,
|
||||
'rel' => $rel
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLinks() {
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $href
|
||||
* @param string $rel
|
||||
* @param string $media
|
||||
*/
|
||||
public function addStyle($href, $rel = 'stylesheet', $media = 'screen', $position = 'header') {
|
||||
$this->styles[$position][$href] = array(
|
||||
'href' => $href,
|
||||
'rel' => $rel,
|
||||
'media' => $media
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStyles($position = 'header') {
|
||||
if (isset($this->styles[$position])) {
|
||||
return $this->styles[$position];
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $href
|
||||
* @param string $position
|
||||
*/
|
||||
public function addScript($href, $position = 'header') {
|
||||
$this->scripts[$position][$href] = $href;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $position
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getScripts($position = 'header') {
|
||||
if (isset($this->scripts[$position])) {
|
||||
return $this->scripts[$position];
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
public function setOgImage($image) {
|
||||
$this->og_image = $image;
|
||||
}
|
||||
|
||||
public function getOgImage() {
|
||||
return $this->og_image;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* Encryption class
|
||||
*/
|
||||
final class Encryption {
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function encrypt($key, $value) {
|
||||
return strtr(base64_encode(openssl_encrypt($value, 'aes-128-cbc', hash('sha256', $key, true))), '+/=', '-_,');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function decrypt($key, $value) {
|
||||
return trim(openssl_decrypt(base64_decode(strtr($value, '-_,', '+/=')), 'aes-128-cbc', hash('sha256', $key, true)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"require": {
|
||||
"phpoffice/phpspreadsheet": "^1.20"
|
||||
}
|
||||
}
|
||||
+703
@@ -0,0 +1,703 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "944e701802c6072df43fb3bdd40a9d1b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "ezyang/htmlpurifier",
|
||||
"version": "v4.14.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ezyang/htmlpurifier.git",
|
||||
"reference": "12ab42bd6e742c70c0a52f7b82477fcd44e64b75"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/12ab42bd6e742c70c0a52f7b82477fcd44e64b75",
|
||||
"reference": "12ab42bd6e742c70c0a52f7b82477fcd44e64b75",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.2"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"HTMLPurifier": "library/"
|
||||
},
|
||||
"files": [
|
||||
"library/HTMLPurifier.composer.php"
|
||||
],
|
||||
"exclude-from-classmap": [
|
||||
"/library/HTMLPurifier/Language/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-2.1-or-later"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Edward Z. Yang",
|
||||
"email": "admin@htmlpurifier.org",
|
||||
"homepage": "http://ezyang.com"
|
||||
}
|
||||
],
|
||||
"description": "Standards compliant HTML filter written in PHP",
|
||||
"homepage": "http://htmlpurifier.org/",
|
||||
"keywords": [
|
||||
"html"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/ezyang/htmlpurifier/issues",
|
||||
"source": "https://github.com/ezyang/htmlpurifier/tree/v4.14.0"
|
||||
},
|
||||
"time": "2021-12-25T01:21:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "maennchen/zipstream-php",
|
||||
"version": "2.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/maennchen/ZipStream-PHP.git",
|
||||
"reference": "c4c5803cc1f93df3d2448478ef79394a5981cc58"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/c4c5803cc1f93df3d2448478ef79394a5981cc58",
|
||||
"reference": "c4c5803cc1f93df3d2448478ef79394a5981cc58",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"myclabs/php-enum": "^1.5",
|
||||
"php": ">= 7.1",
|
||||
"psr/http-message": "^1.0",
|
||||
"symfony/polyfill-mbstring": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-zip": "*",
|
||||
"guzzlehttp/guzzle": ">= 6.3",
|
||||
"mikey179/vfsstream": "^1.6",
|
||||
"phpunit/phpunit": ">= 7.5"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"ZipStream\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Paul Duncan",
|
||||
"email": "pabs@pablotron.org"
|
||||
},
|
||||
{
|
||||
"name": "Jonatan Männchen",
|
||||
"email": "jonatan@maennchen.ch"
|
||||
},
|
||||
{
|
||||
"name": "Jesse Donat",
|
||||
"email": "donatj@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "András Kolesár",
|
||||
"email": "kolesar@kolesar.hu"
|
||||
}
|
||||
],
|
||||
"description": "ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.",
|
||||
"keywords": [
|
||||
"stream",
|
||||
"zip"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/maennchen/ZipStream-PHP/issues",
|
||||
"source": "https://github.com/maennchen/ZipStream-PHP/tree/master"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://opencollective.com/zipstream",
|
||||
"type": "open_collective"
|
||||
}
|
||||
],
|
||||
"time": "2020-05-30T13:11:16+00:00"
|
||||
},
|
||||
{
|
||||
"name": "markbaker/complex",
|
||||
"version": "3.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/MarkBaker/PHPComplex.git",
|
||||
"reference": "ab8bc271e404909db09ff2d5ffa1e538085c0f22"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/ab8bc271e404909db09ff2d5ffa1e538085c0f22",
|
||||
"reference": "ab8bc271e404909db09ff2d5ffa1e538085c0f22",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
|
||||
"phpcompatibility/php-compatibility": "^9.0",
|
||||
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.3",
|
||||
"squizlabs/php_codesniffer": "^3.4"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Complex\\": "classes/src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Mark Baker",
|
||||
"email": "mark@lange.demon.co.uk"
|
||||
}
|
||||
],
|
||||
"description": "PHP Class for working with complex numbers",
|
||||
"homepage": "https://github.com/MarkBaker/PHPComplex",
|
||||
"keywords": [
|
||||
"complex",
|
||||
"mathematics"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/MarkBaker/PHPComplex/issues",
|
||||
"source": "https://github.com/MarkBaker/PHPComplex/tree/3.0.1"
|
||||
},
|
||||
"time": "2021-06-29T15:32:53+00:00"
|
||||
},
|
||||
{
|
||||
"name": "markbaker/matrix",
|
||||
"version": "3.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/MarkBaker/PHPMatrix.git",
|
||||
"reference": "c66aefcafb4f6c269510e9ac46b82619a904c576"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/c66aefcafb4f6c269510e9ac46b82619a904c576",
|
||||
"reference": "c66aefcafb4f6c269510e9ac46b82619a904c576",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
|
||||
"phpcompatibility/php-compatibility": "^9.0",
|
||||
"phpdocumentor/phpdocumentor": "2.*",
|
||||
"phploc/phploc": "^4.0",
|
||||
"phpmd/phpmd": "2.*",
|
||||
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.3",
|
||||
"sebastian/phpcpd": "^4.0",
|
||||
"squizlabs/php_codesniffer": "^3.4"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Matrix\\": "classes/src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Mark Baker",
|
||||
"email": "mark@demon-angel.eu"
|
||||
}
|
||||
],
|
||||
"description": "PHP Class for working with matrices",
|
||||
"homepage": "https://github.com/MarkBaker/PHPMatrix",
|
||||
"keywords": [
|
||||
"mathematics",
|
||||
"matrix",
|
||||
"vector"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/MarkBaker/PHPMatrix/issues",
|
||||
"source": "https://github.com/MarkBaker/PHPMatrix/tree/3.0.0"
|
||||
},
|
||||
"time": "2021-07-01T19:01:15+00:00"
|
||||
},
|
||||
{
|
||||
"name": "myclabs/php-enum",
|
||||
"version": "1.8.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/myclabs/php-enum.git",
|
||||
"reference": "b942d263c641ddb5190929ff840c68f78713e937"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/myclabs/php-enum/zipball/b942d263c641ddb5190929ff840c68f78713e937",
|
||||
"reference": "b942d263c641ddb5190929ff840c68f78713e937",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"php": "^7.3 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"squizlabs/php_codesniffer": "1.*",
|
||||
"vimeo/psalm": "^4.6.2"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"MyCLabs\\Enum\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP Enum contributors",
|
||||
"homepage": "https://github.com/myclabs/php-enum/graphs/contributors"
|
||||
}
|
||||
],
|
||||
"description": "PHP Enum implementation",
|
||||
"homepage": "http://github.com/myclabs/php-enum",
|
||||
"keywords": [
|
||||
"enum"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/myclabs/php-enum/issues",
|
||||
"source": "https://github.com/myclabs/php-enum/tree/1.8.3"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/mnapoli",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/myclabs/php-enum",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-07-05T08:18:36+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoffice/phpspreadsheet",
|
||||
"version": "1.20.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
|
||||
"reference": "44436f270bb134b4a94670f3d020a85dfa0a3c02"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/44436f270bb134b4a94670f3d020a85dfa0a3c02",
|
||||
"reference": "44436f270bb134b4a94670f3d020a85dfa0a3c02",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-ctype": "*",
|
||||
"ext-dom": "*",
|
||||
"ext-fileinfo": "*",
|
||||
"ext-gd": "*",
|
||||
"ext-iconv": "*",
|
||||
"ext-libxml": "*",
|
||||
"ext-mbstring": "*",
|
||||
"ext-simplexml": "*",
|
||||
"ext-xml": "*",
|
||||
"ext-xmlreader": "*",
|
||||
"ext-xmlwriter": "*",
|
||||
"ext-zip": "*",
|
||||
"ext-zlib": "*",
|
||||
"ezyang/htmlpurifier": "^4.13",
|
||||
"maennchen/zipstream-php": "^2.1",
|
||||
"markbaker/complex": "^3.0",
|
||||
"markbaker/matrix": "^3.0",
|
||||
"php": "^7.3 || ^8.0",
|
||||
"psr/http-client": "^1.0",
|
||||
"psr/http-factory": "^1.0",
|
||||
"psr/simple-cache": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
|
||||
"dompdf/dompdf": "^1.0",
|
||||
"friendsofphp/php-cs-fixer": "^3.2",
|
||||
"jpgraph/jpgraph": "^4.0",
|
||||
"mpdf/mpdf": "^8.0",
|
||||
"phpcompatibility/php-compatibility": "^9.3",
|
||||
"phpstan/phpstan": "^1.1",
|
||||
"phpstan/phpstan-phpunit": "^1.0",
|
||||
"phpunit/phpunit": "^8.5 || ^9.0",
|
||||
"squizlabs/php_codesniffer": "^3.6",
|
||||
"tecnickcom/tcpdf": "^6.4"
|
||||
},
|
||||
"suggest": {
|
||||
"dompdf/dompdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)",
|
||||
"jpgraph/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers",
|
||||
"mpdf/mpdf": "Option for rendering PDF with PDF Writer",
|
||||
"tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PhpOffice\\PhpSpreadsheet\\": "src/PhpSpreadsheet"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Maarten Balliauw",
|
||||
"homepage": "https://blog.maartenballiauw.be"
|
||||
},
|
||||
{
|
||||
"name": "Mark Baker",
|
||||
"homepage": "https://markbakeruk.net"
|
||||
},
|
||||
{
|
||||
"name": "Franck Lefevre",
|
||||
"homepage": "https://rootslabs.net"
|
||||
},
|
||||
{
|
||||
"name": "Erik Tilt"
|
||||
},
|
||||
{
|
||||
"name": "Adrien Crivelli"
|
||||
}
|
||||
],
|
||||
"description": "PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine",
|
||||
"homepage": "https://github.com/PHPOffice/PhpSpreadsheet",
|
||||
"keywords": [
|
||||
"OpenXML",
|
||||
"excel",
|
||||
"gnumeric",
|
||||
"ods",
|
||||
"php",
|
||||
"spreadsheet",
|
||||
"xls",
|
||||
"xlsx"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues",
|
||||
"source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/1.20.0"
|
||||
},
|
||||
"time": "2021-11-23T15:23:42+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-client",
|
||||
"version": "1.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/http-client.git",
|
||||
"reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621",
|
||||
"reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.0 || ^8.0",
|
||||
"psr/http-message": "^1.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Http\\Client\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for HTTP clients",
|
||||
"homepage": "https://github.com/php-fig/http-client",
|
||||
"keywords": [
|
||||
"http",
|
||||
"http-client",
|
||||
"psr",
|
||||
"psr-18"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/php-fig/http-client/tree/master"
|
||||
},
|
||||
"time": "2020-06-29T06:28:15+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-factory",
|
||||
"version": "1.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/http-factory.git",
|
||||
"reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be",
|
||||
"reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.0.0",
|
||||
"psr/http-message": "^1.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Http\\Message\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interfaces for PSR-7 HTTP message factories",
|
||||
"keywords": [
|
||||
"factory",
|
||||
"http",
|
||||
"message",
|
||||
"psr",
|
||||
"psr-17",
|
||||
"psr-7",
|
||||
"request",
|
||||
"response"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/php-fig/http-factory/tree/master"
|
||||
},
|
||||
"time": "2019-04-30T12:38:16+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-message",
|
||||
"version": "1.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/http-message.git",
|
||||
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
|
||||
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Http\\Message\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for HTTP messages",
|
||||
"homepage": "https://github.com/php-fig/http-message",
|
||||
"keywords": [
|
||||
"http",
|
||||
"http-message",
|
||||
"psr",
|
||||
"psr-7",
|
||||
"request",
|
||||
"response"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/php-fig/http-message/tree/master"
|
||||
},
|
||||
"time": "2016-08-06T14:39:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/simple-cache",
|
||||
"version": "1.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/simple-cache.git",
|
||||
"reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b",
|
||||
"reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\SimpleCache\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interfaces for simple caching",
|
||||
"keywords": [
|
||||
"cache",
|
||||
"caching",
|
||||
"psr",
|
||||
"psr-16",
|
||||
"simple-cache"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/php-fig/simple-cache/tree/master"
|
||||
},
|
||||
"time": "2017-10-23T01:57:42+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.23.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-mbstring.git",
|
||||
"reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9174a3d80210dca8daa7f31fec659150bbeabfc6",
|
||||
"reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "1.23-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Mbstring\\": ""
|
||||
},
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for the Mbstring extension",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"mbstring",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.23.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-05-27T12:26:48+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.2.0"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
$current_dir = dirname(__FILE__);
|
||||
|
||||
require_once $current_dir . DIRECTORY_SEPARATOR . 'cron_functions.php';
|
||||
|
||||
if ($index = advertise_google_init($current_dir)) {
|
||||
require_once $index;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
function advertise_google_validate() {
|
||||
if (!getenv("ADVERTISE_GOOGLE_CRON")) {
|
||||
die("Not in Command Line." . PHP_EOL);
|
||||
}
|
||||
}
|
||||
|
||||
function advertise_google_chdir($current_dir) {
|
||||
$root_dir = dirname(dirname(dirname($current_dir)));
|
||||
|
||||
chdir($root_dir);
|
||||
|
||||
return $root_dir;
|
||||
}
|
||||
|
||||
function advertise_google_define_route() {
|
||||
define('ADVERTISE_GOOGLE_ROUTE', 'extension/advertise/google/cron');
|
||||
|
||||
$_GET['route'] = ADVERTISE_GOOGLE_ROUTE;
|
||||
}
|
||||
|
||||
function advertise_google_init($current_dir) {
|
||||
// Validate environment
|
||||
advertise_google_validate();
|
||||
|
||||
// Set up default server vars
|
||||
$_SERVER["HTTP_HOST"] = getenv("CUSTOM_SERVER_NAME");
|
||||
$_SERVER["SERVER_NAME"] = getenv("CUSTOM_SERVER_NAME");
|
||||
$_SERVER["SERVER_PORT"] = getenv("CUSTOM_SERVER_PORT");
|
||||
|
||||
putenv("SERVER_NAME=" . $_SERVER["SERVER_NAME"]);
|
||||
|
||||
// Change root dir
|
||||
$root_dir = advertise_google_chdir($current_dir);
|
||||
|
||||
advertise_google_define_route();
|
||||
|
||||
if (file_exists($root_dir . '/index.php')) {
|
||||
return $root_dir . '/index.php';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace googleshopping\Exception;
|
||||
|
||||
class AccessForbidden extends \RuntimeException {
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace googleshopping\Exception;
|
||||
|
||||
class Connection extends \RuntimeException {
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace googleshopping;
|
||||
|
||||
abstract class Library {
|
||||
protected $registry;
|
||||
|
||||
public function __construct($registry) {
|
||||
$this->registry = $registry;
|
||||
}
|
||||
|
||||
public function __get($key) {
|
||||
return $this->registry->get($key);
|
||||
}
|
||||
|
||||
public function __set($key, $value) {
|
||||
$this->registry->set($key, $value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace googleshopping;
|
||||
|
||||
/**
|
||||
* Log class
|
||||
*/
|
||||
class Log {
|
||||
private $handle;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $filename
|
||||
*/
|
||||
public function __construct($filename, $max_size = 8388608) {
|
||||
$file = DIR_LOGS . $filename;
|
||||
|
||||
clearstatcache(true);
|
||||
|
||||
if ((!file_exists($file) && !is_writable(DIR_LOGS)) || (file_exists($file) && !is_writable($file))) {
|
||||
// Do nothing, as we have no permissions
|
||||
return;
|
||||
}
|
||||
|
||||
if (file_exists($file) && filesize($file) >= $max_size) {
|
||||
$mode = 'wb';
|
||||
} else {
|
||||
$mode = 'ab';
|
||||
}
|
||||
|
||||
$this->handle = @fopen(DIR_LOGS . $filename, $mode);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
public function write($message) {
|
||||
if (is_resource($this->handle)) {
|
||||
fwrite($this->handle, date('Y-m-d G:i:s') . ' - ' . print_r($message, true) . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function __destruct() {
|
||||
if (is_resource($this->handle)) {
|
||||
fclose($this->handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace googleshopping\traits;
|
||||
|
||||
use \googleshopping\Googleshopping;
|
||||
|
||||
trait LibraryLoader {
|
||||
protected function loadLibrary($store_id) {
|
||||
$this->registry->set('googleshopping', new Googleshopping($this->registry, $store_id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace googleshopping\traits;
|
||||
|
||||
trait StoreLoader {
|
||||
protected function loadStore($store_id) {
|
||||
$this->registry->set('setting', new \Config());
|
||||
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
foreach ($this->model_setting_setting->getSetting('advertise_google', $store_id) as $key => $value) {
|
||||
$this->setting->set($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,427 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* Image class
|
||||
*/
|
||||
class Image {
|
||||
private $file;
|
||||
private $image;
|
||||
private $width;
|
||||
private $height;
|
||||
private $bits;
|
||||
private $mime;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
*/
|
||||
public function __construct($file) {
|
||||
if (!extension_loaded('gd')) {
|
||||
exit('Error: PHP GD is not installed!');
|
||||
}
|
||||
|
||||
if (is_file($file)) {
|
||||
$this->file = $file;
|
||||
|
||||
$info = getimagesize($file);
|
||||
|
||||
$this->width = $info[0];
|
||||
$this->height = $info[1];
|
||||
$this->bits = isset($info['bits']) ? $info['bits'] : '';
|
||||
$this->mime = isset($info['mime']) ? $info['mime'] : '';
|
||||
|
||||
if ($this->mime == 'image/gif') {
|
||||
$this->image = imagecreatefromgif($file);
|
||||
} elseif ($this->mime == 'image/png') {
|
||||
$this->image = imagecreatefrompng($file);
|
||||
} elseif ($this->mime == 'image/jpeg') {
|
||||
$this->image = imagecreatefromjpeg($file);
|
||||
} elseif ($this->mime == 'image/webp') {
|
||||
$this->image = imagecreatefromwebp($file);
|
||||
}
|
||||
} else {
|
||||
error_log('Error: Could not load image ' . $file . '!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFile() {
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getImage() {
|
||||
return $this->image;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWidth() {
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHeight() {
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBits() {
|
||||
return $this->bits;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMime() {
|
||||
return $this->mime;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $file
|
||||
* @param int $quality
|
||||
*/
|
||||
public function save($file, int $quality = 90) {
|
||||
$info = pathinfo($file);
|
||||
|
||||
$extension = strtolower($info['extension']);
|
||||
|
||||
if (is_object($this->image) || is_resource($this->image)) {
|
||||
if ($extension == 'jpeg' || $extension == 'jpg') {
|
||||
imagejpeg($this->image, $file, $quality);
|
||||
} elseif ($extension == 'png') {
|
||||
imagepng($this->image, $file);
|
||||
} elseif ($extension == 'gif') {
|
||||
imagegif($this->image, $file);
|
||||
} elseif ($extension == 'webp') {
|
||||
imagewebp($this->image, $file);
|
||||
}
|
||||
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
* @param string $default
|
||||
*/
|
||||
|
||||
public function cropsize($width = 0, $height = 0) {
|
||||
|
||||
if (!$this->width || !$this->height) {
|
||||
return;
|
||||
}
|
||||
|
||||
//afmetingen bepalen
|
||||
$photo_width = $this->width;
|
||||
$photo_height = $this->height;
|
||||
|
||||
$new_width = $width;
|
||||
$new_height = $height;
|
||||
|
||||
//als foto te hoog is
|
||||
if (($photo_width/$new_width) < ($photo_height/$new_height)) {
|
||||
|
||||
$from_y = ceil(($photo_height - ($new_height * $photo_width / $new_width))/2);
|
||||
$from_x = '0';
|
||||
$photo_y = ceil(($new_height * $photo_width / $new_width));
|
||||
$photo_x = $photo_width;
|
||||
|
||||
}
|
||||
|
||||
//als foto te breed is
|
||||
if (($photo_height/$new_height) < ($photo_width/$new_width)) {
|
||||
|
||||
$from_x = ceil(($photo_width - ($new_width * $photo_height / $new_height))/2);
|
||||
$from_y = '0';
|
||||
$photo_x = ceil(($new_width * $photo_height / $new_height));
|
||||
$photo_y = $photo_height;
|
||||
|
||||
}
|
||||
|
||||
//als verhoudingen gelijk zijn
|
||||
if (($photo_width/$new_width) == ($photo_height/$new_height)) {
|
||||
|
||||
$from_x = ceil(($photo_width - ($new_width * $photo_height / $new_height))/2);
|
||||
$from_y = '0';
|
||||
$photo_x = ceil(($new_width * $photo_height / $new_height));
|
||||
$photo_y = $photo_height;
|
||||
|
||||
}
|
||||
|
||||
|
||||
$image_old = $this->image;
|
||||
$this->image = imagecreatetruecolor($width, $height);
|
||||
|
||||
if (isset($this->mime) && ($this->mime == 'image/png' OR $this->mime == 'image/webp')) {
|
||||
imagealphablending($this->image, false);
|
||||
imagesavealpha($this->image, true);
|
||||
$background = imagecolorallocatealpha($this->image, 255, 255, 255, 127);
|
||||
imagecolortransparent($this->image, $background);
|
||||
} else {
|
||||
|
||||
$background = imagecolorallocate($this->image, 255, 255, 255);
|
||||
}
|
||||
|
||||
imagefilledrectangle($this->image, 0, 0, $width, $height, $background);
|
||||
|
||||
|
||||
imagecopyresampled($this->image, $image_old, 0, 0, $from_x, $from_y, $new_width, $new_height, $photo_x, $photo_y);
|
||||
imagedestroy($image_old);
|
||||
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
|
||||
|
||||
}
|
||||
public function resize(int $width = 0, int $height = 0, $default = '') {
|
||||
if (!$this->width || !$this->height) {
|
||||
return;
|
||||
}
|
||||
|
||||
$xpos = 0;
|
||||
$ypos = 0;
|
||||
$scale = 1;
|
||||
|
||||
$scale_w = $width / $this->width;
|
||||
$scale_h = $height / $this->height;
|
||||
|
||||
/* $default = 'w';
|
||||
if ($scale_h > $scale_w) {
|
||||
$default = 'h';
|
||||
} */
|
||||
|
||||
if ($default == 'w') {
|
||||
$scale = $scale_w;
|
||||
} elseif ($default == 'h') {
|
||||
$scale = $scale_h;
|
||||
} else {
|
||||
$scale = min($scale_w, $scale_h);
|
||||
}
|
||||
|
||||
if ($scale == 1 && $scale_h == $scale_w && ($this->mime != 'image/png' && $this->mime != 'image/webp')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$new_width = (int)($this->width * $scale);
|
||||
$new_height = (int)($this->height * $scale);
|
||||
$xpos = (int)(($width - $new_width) / 2);
|
||||
$ypos = (int)(($height - $new_height) / 2);
|
||||
|
||||
$image_old = $this->image;
|
||||
$this->image = imagecreatetruecolor($width, $height);
|
||||
|
||||
if ($this->mime == 'image/png') {
|
||||
imagealphablending($this->image, false);
|
||||
imagesavealpha($this->image, true);
|
||||
|
||||
$background = imagecolorallocatealpha($this->image, 255, 255, 255, 127);
|
||||
|
||||
imagecolortransparent($this->image, $background);
|
||||
|
||||
} else if ($this->mime == 'image/webp') {
|
||||
imagealphablending($this->image, false);
|
||||
imagesavealpha($this->image, true);
|
||||
|
||||
$background = imagecolorallocatealpha($this->image, 255, 255, 255, 127);
|
||||
|
||||
imagecolortransparent($this->image, $background);
|
||||
} else {
|
||||
$background = imagecolorallocate($this->image, 255, 255, 255);
|
||||
}
|
||||
|
||||
imagefilledrectangle($this->image, 0, 0, $width, $height, $background);
|
||||
|
||||
imagecopyresampled($this->image, $image_old, $xpos, $ypos, 0, 0, $new_width, $new_height, $this->width, $this->height);
|
||||
imagedestroy($image_old);
|
||||
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $watermark
|
||||
* @param string $position
|
||||
*/
|
||||
public function watermark($watermark, $position = 'bottomright') {
|
||||
switch($position) {
|
||||
case 'topleft':
|
||||
$watermark_pos_x = 0;
|
||||
$watermark_pos_y = 0;
|
||||
break;
|
||||
case 'topcenter':
|
||||
$watermark_pos_x = intval(($this->width - $watermark->getWidth()) / 2);
|
||||
$watermark_pos_y = 0;
|
||||
break;
|
||||
case 'topright':
|
||||
$watermark_pos_x = $this->width - $watermark->getWidth();
|
||||
$watermark_pos_y = 0;
|
||||
break;
|
||||
case 'middleleft':
|
||||
$watermark_pos_x = 0;
|
||||
$watermark_pos_y = intval(($this->height - $watermark->getHeight()) / 2);
|
||||
break;
|
||||
case 'middlecenter':
|
||||
$watermark_pos_x = intval(($this->width - $watermark->getWidth()) / 2);
|
||||
$watermark_pos_y = intval(($this->height - $watermark->getHeight()) / 2);
|
||||
break;
|
||||
case 'middleright':
|
||||
$watermark_pos_x = $this->width - $watermark->getWidth();
|
||||
$watermark_pos_y = intval(($this->height - $watermark->getHeight()) / 2);
|
||||
break;
|
||||
case 'bottomleft':
|
||||
$watermark_pos_x = 0;
|
||||
$watermark_pos_y = $this->height - $watermark->getHeight();
|
||||
break;
|
||||
case 'bottomcenter':
|
||||
$watermark_pos_x = intval(($this->width - $watermark->getWidth()) / 2);
|
||||
$watermark_pos_y = $this->height - $watermark->getHeight();
|
||||
break;
|
||||
case 'bottomright':
|
||||
$watermark_pos_x = $this->width - $watermark->getWidth();
|
||||
$watermark_pos_y = $this->height - $watermark->getHeight();
|
||||
break;
|
||||
}
|
||||
|
||||
imagealphablending( $this->image, true);
|
||||
imagesavealpha( $this->image, true);
|
||||
imagecopy($this->image, $watermark->getImage(), $watermark_pos_x, $watermark_pos_y, 0, 0, $watermark->getWidth(), $watermark->getHeight());
|
||||
|
||||
imagedestroy($watermark->getImage());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param int $top_x
|
||||
* @param int $top_y
|
||||
* @param int $bottom_x
|
||||
* @param int $bottom_y
|
||||
*/
|
||||
public function crop($top_x, $top_y, $bottom_x, $bottom_y) {
|
||||
$image_old = $this->image;
|
||||
$this->image = imagecreatetruecolor($bottom_x - $top_x, $bottom_y - $top_y);
|
||||
|
||||
imagecopy($this->image, $image_old, 0, 0, $top_x, $top_y, $this->width, $this->height);
|
||||
imagedestroy($image_old);
|
||||
|
||||
$this->width = $bottom_x - $top_x;
|
||||
$this->height = $bottom_y - $top_y;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param int $degree
|
||||
* @param string $color
|
||||
*/
|
||||
public function rotate($degree, $color = 'FFFFFF') {
|
||||
$rgb = $this->html2rgb($color);
|
||||
|
||||
$this->image = imagerotate($this->image, $degree, imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2]));
|
||||
|
||||
$this->width = imagesx($this->image);
|
||||
$this->height = imagesy($this->image);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private function filter() {
|
||||
$args = func_get_args();
|
||||
|
||||
call_user_func_array('imagefilter', $args);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $text
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
* @param int $size
|
||||
* @param string $color
|
||||
*/
|
||||
private function text($text, $x = 0, $y = 0, $size = 5, $color = '000000') {
|
||||
$rgb = $this->html2rgb($color);
|
||||
|
||||
imagestring($this->image, $size, $x, $y, $text, imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2]));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param object $merge
|
||||
* @param object $x
|
||||
* @param object $y
|
||||
* @param object $opacity
|
||||
*/
|
||||
private function merge($merge, $x = 0, $y = 0, $opacity = 100) {
|
||||
imagecopymerge($this->image, $merge->getImage(), $x, $y, 0, 0, $merge->getWidth(), $merge->getHeight(), $opacity);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $color
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function html2rgb($color) {
|
||||
if ($color[0] == '#') {
|
||||
$color = substr($color, 1);
|
||||
}
|
||||
|
||||
if (strlen($color) == 6) {
|
||||
list($r, $g, $b) = [$color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5]];
|
||||
} elseif (strlen($color) == 3) {
|
||||
list($r, $g, $b) = [$color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2]];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$r = hexdec($r);
|
||||
$g = hexdec($g);
|
||||
$b = hexdec($b);
|
||||
|
||||
return [$r, $g, $b];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* Language class
|
||||
*/
|
||||
class Language {
|
||||
private $default = 'en-gb';
|
||||
private $directory;
|
||||
public $data = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
*/
|
||||
public function __construct($directory = '') {
|
||||
$this->directory = $directory;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get($key) {
|
||||
return (isset($this->data[$key]) ? $this->data[$key] : $key);
|
||||
}
|
||||
|
||||
public function set($key, $value) {
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $filename
|
||||
* @param string $key
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function load($filename, $key = '') {
|
||||
if (!$key) {
|
||||
$_ = array();
|
||||
|
||||
$file = DIR_LANGUAGE . $this->default . '/' . $filename . '.php';
|
||||
|
||||
if (is_file($file)) {
|
||||
require(modification($file));
|
||||
}
|
||||
|
||||
$file = DIR_LANGUAGE . $this->directory . '/' . $filename . '.php';
|
||||
|
||||
if (is_file($file)) {
|
||||
require(modification($file));
|
||||
}
|
||||
|
||||
$this->data = array_merge($this->data, $_);
|
||||
} else {
|
||||
// Put the language into a sub key
|
||||
$this->data[$key] = new Language($this->directory);
|
||||
$this->data[$key]->load($filename);
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* Log class
|
||||
*/
|
||||
class Log {
|
||||
private $handle;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $filename
|
||||
*/
|
||||
public function __construct($filename) {
|
||||
$this->handle = fopen(DIR_LOGS . $filename, 'a');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
public function write($message) {
|
||||
fwrite($this->handle, date('Y-m-d G:i:s') . ' - ' . print_r($message, true) . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function __destruct() {
|
||||
fclose($this->handle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* Mail class
|
||||
*/
|
||||
class Mail {
|
||||
protected $to;
|
||||
protected $from;
|
||||
protected $sender;
|
||||
protected $reply_to;
|
||||
protected $subject;
|
||||
protected $text;
|
||||
protected $html;
|
||||
protected $attachments = array();
|
||||
public $parameter;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $adaptor
|
||||
*
|
||||
*/
|
||||
public function __construct($adaptor = 'mail') {
|
||||
$class = 'Mail\\' . $adaptor;
|
||||
|
||||
if (class_exists($class)) {
|
||||
$this->adaptor = new $class();
|
||||
} else {
|
||||
trigger_error('Error: Could not load mail adaptor ' . $adaptor . '!');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param mixed $to
|
||||
*/
|
||||
public function setTo($to) {
|
||||
$this->to = $to;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $from
|
||||
*/
|
||||
public function setFrom($from) {
|
||||
$this->from = $from;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $sender
|
||||
*/
|
||||
public function setSender($sender) {
|
||||
$this->sender = $sender;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $reply_to
|
||||
*/
|
||||
public function setReplyTo($reply_to) {
|
||||
$this->reply_to = $reply_to;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $subject
|
||||
*/
|
||||
public function setSubject($subject) {
|
||||
$this->subject = $subject;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $html
|
||||
*/
|
||||
public function setHtml($html) {
|
||||
$this->html = $html;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $filename
|
||||
*/
|
||||
public function addAttachment($filename) {
|
||||
$this->attachments[] = $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function send() {
|
||||
if (!$this->to) {
|
||||
throw new \Exception('Error: E-Mail to required!');
|
||||
}
|
||||
|
||||
if (!$this->from) {
|
||||
throw new \Exception('Error: E-Mail from required!');
|
||||
}
|
||||
|
||||
if (!$this->sender) {
|
||||
throw new \Exception('Error: E-Mail sender required!');
|
||||
}
|
||||
|
||||
if (!$this->subject) {
|
||||
throw new \Exception('Error: E-Mail subject required!');
|
||||
}
|
||||
|
||||
if ((!$this->text) && (!$this->html)) {
|
||||
throw new \Exception('Error: E-Mail message required!');
|
||||
}
|
||||
|
||||
foreach (get_object_vars($this) as $key => $value) {
|
||||
$this->adaptor->$key = $value;
|
||||
}
|
||||
|
||||
$this->adaptor->send();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace Mail;
|
||||
class Mail {
|
||||
public function send() {
|
||||
if (is_array($this->to)) {
|
||||
$to = implode(',', $this->to);
|
||||
} else {
|
||||
$to = $this->to;
|
||||
}
|
||||
|
||||
$boundary = '----=_NextPart_' . md5(time());
|
||||
|
||||
$header = 'MIME-Version: 1.0' . 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 .= '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 .= '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;
|
||||
$message .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;
|
||||
|
||||
if ($this->text) {
|
||||
$message .= $this->text . PHP_EOL;
|
||||
} else {
|
||||
$message .= 'This is a HTML email and your email client software does not support HTML email!' . PHP_EOL;
|
||||
}
|
||||
|
||||
$message .= '--' . $boundary . '_alt' . PHP_EOL;
|
||||
$message .= 'Content-Type: text/html; charset="utf-8"' . PHP_EOL;
|
||||
$message .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;
|
||||
$message .= $this->html . PHP_EOL;
|
||||
$message .= '--' . $boundary . '_alt--' . PHP_EOL;
|
||||
}
|
||||
|
||||
foreach ($this->attachments as $attachment) {
|
||||
if (file_exists($attachment)) {
|
||||
$handle = fopen($attachment, 'r');
|
||||
|
||||
$content = fread($handle, filesize($attachment));
|
||||
|
||||
fclose($handle);
|
||||
|
||||
$message .= '--' . $boundary . PHP_EOL;
|
||||
$message .= 'Content-Type: application/octet-stream; name="' . basename($attachment) . '"' . PHP_EOL;
|
||||
$message .= 'Content-Transfer-Encoding: base64' . PHP_EOL;
|
||||
$message .= 'Content-Disposition: attachment; filename="' . basename($attachment) . '"' . PHP_EOL;
|
||||
$message .= 'Content-ID: <' . urlencode(basename($attachment)) . '>' . PHP_EOL;
|
||||
$message .= 'X-Attachment-Id: ' . urlencode(basename($attachment)) . PHP_EOL . PHP_EOL;
|
||||
$message .= chunk_split(base64_encode($content));
|
||||
}
|
||||
}
|
||||
|
||||
$message .= '--' . $boundary . '--' . PHP_EOL;
|
||||
|
||||
ini_set('sendmail_from', $this->from);
|
||||
|
||||
if ($this->parameter) {
|
||||
mail($to, '=?UTF-8?B?' . base64_encode($this->subject) . '?=', $message, $header, $this->parameter);
|
||||
} else {
|
||||
mail($to, '=?UTF-8?B?' . base64_encode($this->subject) . '?=', $message, $header);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
namespace Mail;
|
||||
class Smtp {
|
||||
public $smtp_hostname;
|
||||
public $smtp_username;
|
||||
public $smtp_password;
|
||||
public $smtp_port = 25;
|
||||
public $smtp_timeout = 5;
|
||||
public $max_attempts = 3;
|
||||
public $verp = false;
|
||||
|
||||
public function send() {
|
||||
if (is_array($this->to)) {
|
||||
$to = implode(',', $this->to);
|
||||
} else {
|
||||
$to = $this->to;
|
||||
}
|
||||
|
||||
$boundary = '----=_NextPart_' . md5(time());
|
||||
|
||||
$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 .= '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 .= '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;
|
||||
$message .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;
|
||||
|
||||
if ($this->text) {
|
||||
$message .= $this->text . PHP_EOL;
|
||||
} else {
|
||||
$message .= 'This is a HTML email and your email client software does not support HTML email!' . PHP_EOL;
|
||||
}
|
||||
|
||||
$message .= '--' . $boundary . '_alt' . PHP_EOL;
|
||||
$message .= 'Content-Type: text/html; charset="utf-8"' . PHP_EOL;
|
||||
$message .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;
|
||||
$message .= $this->html . PHP_EOL;
|
||||
$message .= '--' . $boundary . '_alt--' . PHP_EOL;
|
||||
}
|
||||
|
||||
foreach ($this->attachments as $attachment) {
|
||||
if (file_exists($attachment)) {
|
||||
$handle = fopen($attachment, 'r');
|
||||
|
||||
$content = fread($handle, filesize($attachment));
|
||||
|
||||
fclose($handle);
|
||||
|
||||
$message .= '--' . $boundary . PHP_EOL;
|
||||
$message .= 'Content-Type: application/octet-stream; name="' . basename($attachment) . '"' . PHP_EOL;
|
||||
$message .= 'Content-Transfer-Encoding: base64' . PHP_EOL;
|
||||
$message .= 'Content-Disposition: attachment; filename="' . basename($attachment) . '"' . PHP_EOL;
|
||||
$message .= 'Content-ID: <' . urlencode(basename($attachment)) . '>' . PHP_EOL;
|
||||
$message .= 'X-Attachment-Id: ' . urlencode(basename($attachment)) . PHP_EOL . PHP_EOL;
|
||||
$message .= chunk_split(base64_encode($content));
|
||||
}
|
||||
}
|
||||
|
||||
$message .= '--' . $boundary . '--' . PHP_EOL;
|
||||
|
||||
if (substr($this->smtp_hostname, 0, 3) == 'tls') {
|
||||
$hostname = substr($this->smtp_hostname, 6);
|
||||
} else {
|
||||
$hostname = $this->smtp_hostname;
|
||||
}
|
||||
|
||||
$handle = fsockopen($hostname, $this->smtp_port, $errno, $errstr, $this->smtp_timeout);
|
||||
|
||||
if (!$handle) {
|
||||
throw new \Exception('Error: ' . $errstr . ' (' . $errno . ')');
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
fputs($handle, 'EHLO ' . getenv('SERVER_NAME') . "\r\n");
|
||||
|
||||
$reply = '';
|
||||
|
||||
while ($line = fgets($handle, 515)) {
|
||||
$reply .= $line;
|
||||
|
||||
//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) == ' ') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (substr($reply, 0, 3) != 250) {
|
||||
throw new \Exception('Error: EHLO not accepted from server!');
|
||||
}
|
||||
|
||||
if (substr($this->smtp_hostname, 0, 3) == 'tls') {
|
||||
fputs($handle, 'STARTTLS' . "\r\n");
|
||||
|
||||
$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)) {
|
||||
fputs($handle, 'EHLO ' . getenv('SERVER_NAME') . "\r\n");
|
||||
|
||||
$this->handleReply($handle, 250, 'Error: EHLO not accepted from server!');
|
||||
|
||||
fputs($handle, 'AUTH LOGIN' . "\r\n");
|
||||
|
||||
$this->handleReply($handle, 334, 'Error: AUTH LOGIN not accepted from server!');
|
||||
|
||||
fputs($handle, base64_encode($this->smtp_username) . "\r\n");
|
||||
|
||||
$this->handleReply($handle, 334, 'Error: Username not accepted from server!');
|
||||
|
||||
fputs($handle, base64_encode($this->smtp_password) . "\r\n");
|
||||
|
||||
$this->handleReply($handle, 235, 'Error: Password not accepted from server!');
|
||||
|
||||
} else {
|
||||
fputs($handle, 'HELO ' . getenv('SERVER_NAME') . "\r\n");
|
||||
|
||||
$this->handleReply($handle, 250, 'Error: HELO not accepted from server!');
|
||||
}
|
||||
|
||||
if ($this->verp) {
|
||||
fputs($handle, 'MAIL FROM: <' . $this->smtp_username . '>XVERP' . "\r\n");
|
||||
} else {
|
||||
fputs($handle, 'MAIL FROM: <' . $this->smtp_username . '>' . "\r\n");
|
||||
}
|
||||
|
||||
$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 = $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!');
|
||||
}
|
||||
} else {
|
||||
foreach ($this->to as $recipient) {
|
||||
fputs($handle, 'RCPT TO: <' . $recipient . '>' . "\r\n");
|
||||
|
||||
$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!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fputs($handle, 'DATA' . "\r\n");
|
||||
|
||||
$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, $length);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (substr(PHP_OS, 0, 3) != 'WIN') {
|
||||
fputs($handle, $result . "\r\n");
|
||||
} else {
|
||||
fputs($handle, str_replace("\n", "\r\n", $result) . "\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fputs($handle, '.' . "\r\n");
|
||||
|
||||
$this->handleReply($handle, 250, 'Error: DATA not accepted from server!');
|
||||
|
||||
fputs($handle, 'QUIT' . "\r\n");
|
||||
|
||||
$this->handleReply($handle, 221, 'Error: QUIT not accepted from server!');
|
||||
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
|
||||
private function handleReply($handle, $status_code = false, $error_text = false, $counter = 0) {
|
||||
$reply = '';
|
||||
|
||||
while (($line = fgets($handle, 515)) !== false) {
|
||||
$reply .= $line;
|
||||
|
||||
if (substr($line, 3, 1) == ' ') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle slowish server responses (generally due to policy servers)
|
||||
if (!$line && empty($reply) && $counter < $this->max_attempts) {
|
||||
sleep(1);
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pagination class
|
||||
*/
|
||||
class Pagination {
|
||||
public $total = 0;
|
||||
public $page = 1;
|
||||
public $limit = 20;
|
||||
public $num_links = 8;
|
||||
public $url = '';
|
||||
public $text_first = '|<';
|
||||
public $text_last = '>|';
|
||||
public $text_next = '>';
|
||||
public $text_prev = '<';
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return text
|
||||
*/
|
||||
public function render() {
|
||||
$total = $this->total;
|
||||
|
||||
if ($this->page < 1) {
|
||||
$page = 1;
|
||||
} else {
|
||||
$page = $this->page;
|
||||
}
|
||||
|
||||
if (!(int)$this->limit) {
|
||||
$limit = 10;
|
||||
} else {
|
||||
$limit = $this->limit;
|
||||
}
|
||||
|
||||
$num_links = $this->num_links;
|
||||
$num_pages = ceil($total / $limit);
|
||||
|
||||
$this->url = str_replace('%7Bpage%7D', '{page}', $this->url);
|
||||
|
||||
$output = '<ul class="pagination">';
|
||||
|
||||
if ($page > 1) {
|
||||
$output .= '<li class="btn px-3 py-2"><a href="' . str_replace(array('&page={page}', '?page={page}', '&page={page}'), '', $this->url) . '">' . $this->text_first . '</a></li>';
|
||||
|
||||
if ($page - 1 === 1) {
|
||||
$output .= '<li class="btn px-3 py-2"><a href="' . str_replace(array('&page={page}', '?page={page}', '&page={page}'), '', $this->url) . '">' . $this->text_prev . '</a></li>';
|
||||
} else {
|
||||
$output .= '<li class="btn px-3 py-2"><a href="' . str_replace('{page}', $page - 1, $this->url) . '">' . $this->text_prev . '</a></li>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($num_pages > 1) {
|
||||
if ($num_pages <= $num_links) {
|
||||
$start = 1;
|
||||
$end = $num_pages;
|
||||
} else {
|
||||
$start = $page - floor($num_links / 2);
|
||||
$end = $page + floor($num_links / 2);
|
||||
|
||||
if ($start < 1) {
|
||||
$end += abs($start) + 1;
|
||||
$start = 1;
|
||||
}
|
||||
|
||||
if ($end > $num_pages) {
|
||||
$start -= ($end - $num_pages);
|
||||
$end = $num_pages;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = $start; $i <= $end; $i++) {
|
||||
if ($page == $i) {
|
||||
$output .= '<li class="btn btn-dark active px-3 py-2"><span>' . $i . '</span></li>';
|
||||
} else {
|
||||
if ($i === 1) {
|
||||
$output .= '<li class="btn px-3 py-2"><a href="' . str_replace(array('&page={page}', '?page={page}', '&page={page}'), '', $this->url) . '">' . $i . '</a></li>';
|
||||
} else {
|
||||
$output .= '<li class="btn px-3 py-2"><a href="' . str_replace('{page}', $i, $this->url) . '">' . $i . '</a></li>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($page < $num_pages) {
|
||||
$output .= '<li class="btn px-3 py-2"><a href="' . str_replace('{page}', $page + 1, $this->url) . '">' . $this->text_next . '</a></li>';
|
||||
$output .= '<li class="btn px-3 py-2"><a href="' . str_replace('{page}', $num_pages, $this->url) . '">' . $this->text_last . '</a></li>';
|
||||
}
|
||||
|
||||
$output .= '</ul>';
|
||||
|
||||
if ($num_pages > 1) {
|
||||
return $output;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* Request class
|
||||
*/
|
||||
class Request {
|
||||
public $get = array();
|
||||
public $post = array();
|
||||
public $cookie = array();
|
||||
public $files = array();
|
||||
public $server = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->get = $this->clean($_GET);
|
||||
$this->post = $this->clean($_POST);
|
||||
$this->request = $this->clean($_REQUEST);
|
||||
$this->cookie = $this->clean($_COOKIE);
|
||||
$this->files = $this->clean($_FILES);
|
||||
$this->server = $this->clean($_SERVER);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function clean($data) {
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $key => $value) {
|
||||
unset($data[$key]);
|
||||
|
||||
$data[$this->clean($key)] = $this->clean($value);
|
||||
}
|
||||
} else {
|
||||
$data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* Response class
|
||||
*/
|
||||
class Response {
|
||||
private $headers = array();
|
||||
private $level = 0;
|
||||
private $output;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $header
|
||||
*
|
||||
*/
|
||||
public function addHeader($header) {
|
||||
$this->headers[] = $header;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $url
|
||||
* @param int $status
|
||||
*
|
||||
*/
|
||||
public function redirect($url, $status = 302) {
|
||||
header('Location: ' . str_replace(array('&', "\n", "\r"), array('&', '', ''), $url), true, $status);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param int $level
|
||||
*/
|
||||
public function setCompression($level) {
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOutput() {
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $output
|
||||
*/
|
||||
public function setOutput($output) {
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $data
|
||||
* @param int $level
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function compress($data, $level = 0) {
|
||||
if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false)) {
|
||||
$encoding = 'gzip';
|
||||
}
|
||||
|
||||
if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false)) {
|
||||
$encoding = 'x-gzip';
|
||||
}
|
||||
|
||||
if (!isset($encoding) || ($level < -1 || $level > 9)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
if (!extension_loaded('zlib') || ini_get('zlib.output_compression')) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
if (headers_sent()) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
if (connection_status()) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$this->addHeader('Content-Encoding: ' . $encoding);
|
||||
|
||||
return gzencode($data, (int)$level);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function output() {
|
||||
if ($this->output) {
|
||||
$output = $this->level ? $this->compress($this->output, $this->level) : $this->output;
|
||||
|
||||
if (!headers_sent()) {
|
||||
foreach ($this->headers as $header) {
|
||||
header($header, true);
|
||||
}
|
||||
}
|
||||
|
||||
echo $output;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,731 @@
|
||||
<?php
|
||||
/**
|
||||
* @package SeoPro
|
||||
* @author Oclabs
|
||||
* @copyright Copyright (c) 2017, Oclabs (https://www.oclabs.pro/)
|
||||
* @copyright Copyright (c) 2021, ocStore (https://ocstore.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
*/
|
||||
|
||||
// ALTER TABLE `oc_product_to_category` ADD `main_category_id` TINYINT(1) NOT NULL DEFAULT '0' AFTER `category_id`;
|
||||
|
||||
class SeoPro {
|
||||
|
||||
private $config;
|
||||
private $ajax = false;
|
||||
private $request;
|
||||
private $registry;
|
||||
private $response;
|
||||
private $url;
|
||||
private $session;
|
||||
private $db;
|
||||
private $cat_tree = [];
|
||||
private $keywords = [];
|
||||
private $queries = [];
|
||||
private $product_categories = [];
|
||||
private $valide_get_param;
|
||||
|
||||
public function __construct($registry) {
|
||||
$this->detectAjax();
|
||||
$this->registry = $registry;
|
||||
$this->config = $registry->get('config');
|
||||
|
||||
if(!$this->config->get('config_seo_pro'))
|
||||
return;
|
||||
|
||||
$this->request = $registry->get('request');
|
||||
$this->session = $registry->get('session');
|
||||
$this->response = $registry->get('response');
|
||||
$this->url = $registry->get('url');
|
||||
$this->db = $registry->get('db');
|
||||
$this->cache = $registry->get('cache');
|
||||
$this->detectPostfix();
|
||||
$this->detectLanguage();
|
||||
$this->initHelpers();
|
||||
if ($this->config->get('config_valide_param_flag')) {
|
||||
$params = explode ("\r\n", $this->config->get('config_valide_params'));
|
||||
if(!empty($params)) {
|
||||
$this->valide_get_param = $params;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function prepareRoute($parts) {
|
||||
|
||||
if (!empty($parts) && is_array($parts)) {
|
||||
|
||||
foreach($parts as $id => $part) {
|
||||
|
||||
if($this->config->get('config_seopro_lowercase'))
|
||||
$parts[$id] = utf8_strtolower($part);
|
||||
|
||||
if($parts[$id]) {
|
||||
|
||||
$query = $this->getQueryByKeyword($parts[$id]);
|
||||
|
||||
$url = explode('=', $query);
|
||||
|
||||
if(!empty($url[0])) {
|
||||
|
||||
if(!in_array($url[0], ['category_id', 'product_id', 'manufacturer_id', 'information_id', 'article_id', 'blog_category_id', 'service_id'])) {
|
||||
return $parts;
|
||||
}
|
||||
|
||||
if ($url[0] == 'category_id') {
|
||||
if (!isset($this->request->get['path'])) {
|
||||
$this->request->get['path'] = $url[1];
|
||||
} else {
|
||||
$this->request->get['path'] .= '_' . $url[1];
|
||||
}
|
||||
} elseif ($url[0] == 'blog_category_id') {
|
||||
if (!isset($this->request->get['blog_category_id'])) {
|
||||
$this->request->get['blog_category_id'] = $url[1];
|
||||
} else {
|
||||
$this->request->get['blog_category_id'] .= '_' . $url[1];
|
||||
}
|
||||
} elseif (count($url) > 1) {
|
||||
$this->request->get[$url[0]] = $url[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($parts[$id]);
|
||||
}
|
||||
|
||||
if(!$query) {
|
||||
$this->request->get['route'] = 'error/not_found';
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->get['product_id'])) {
|
||||
if(isset($this->request->get['path'])) {
|
||||
unset($this->request->get['path']);
|
||||
};
|
||||
$path = $this->getCategoryByProduct($this->request->get['product_id']);
|
||||
if ($path) $this->request->get['path'] = $path;
|
||||
$this->request->get['route'] = 'product/product';
|
||||
} elseif (isset($this->request->get['path'])) {
|
||||
$this->request->get['route'] = 'product/category';
|
||||
} elseif (isset($this->request->get['manufacturer_id'])) {
|
||||
$this->request->get['route'] = 'product/manufacturer/info';
|
||||
} elseif (isset($this->request->get['information_id'])) {
|
||||
$this->request->get['route'] = 'information/information';
|
||||
}
|
||||
|
||||
//blog
|
||||
if (isset($this->request->get['article_id'])) {
|
||||
if(isset($this->request->get['blog_category_id'])) {
|
||||
unset($this->request->get['blog_category_id']);
|
||||
};
|
||||
$blog_category_path = $this->getBlogPathByArticle($this->request->get['article_id']);
|
||||
if ($blog_category_path) $this->request->get['blog_category_id'] = $blog_category_path;
|
||||
$this->request->get['route'] = 'blog/article';
|
||||
} elseif (isset($this->request->get['blog_category_id'])) {
|
||||
$this->request->get['route'] = 'blog/category';
|
||||
}
|
||||
//end blog
|
||||
|
||||
//services
|
||||
if (isset($this->request->get['service_id'])) {
|
||||
$this->request->get['route'] = 'service/service/info';
|
||||
}
|
||||
//end services
|
||||
|
||||
return $parts;
|
||||
}
|
||||
|
||||
public function baseRewrite($data, $language_id) {
|
||||
|
||||
$url = null;
|
||||
$postfix = null;
|
||||
$language_id = (int)$this->config->get('config_language_id');
|
||||
|
||||
switch ($data['route']) {
|
||||
case 'product/product':
|
||||
if (isset($data['product_id'])) {
|
||||
$route = 'product/product';
|
||||
$path = '';
|
||||
$product_id = $data['product_id'];
|
||||
if (isset($data['path']) || $this->config->get('config_seo_url_include_path')) {
|
||||
$path = $this->getCategoryByProduct($product_id);
|
||||
}
|
||||
|
||||
//start add valide get-param
|
||||
if ($this->valide_get_param) {
|
||||
$valide_get_param_data = [];
|
||||
foreach($this->valide_get_param as $get_param) {
|
||||
if (isset($data[$get_param])) {
|
||||
$valide_get_param_data[$get_param] = $data[$get_param];
|
||||
$this->response->addHeader('X-Robots-Tag: noindex');
|
||||
}
|
||||
};
|
||||
}
|
||||
//end add valide get-param
|
||||
|
||||
unset($data);
|
||||
$data['route'] = $route;
|
||||
|
||||
if ($path && $this->config->get('config_seo_url_include_path')) {
|
||||
$data['path'] = $path;
|
||||
}
|
||||
|
||||
$data['product_id'] = $product_id;
|
||||
//start add valide get-param
|
||||
if ($this->valide_get_param) {
|
||||
$data = array_merge($data, $valide_get_param_data);
|
||||
}
|
||||
//end add valide get-param
|
||||
}
|
||||
break;
|
||||
//blog
|
||||
|
||||
case 'blog/article':
|
||||
if (isset($data['article_id'])) {
|
||||
$route = 'blog/article';
|
||||
$blog_path = '';
|
||||
$article_id = $data['article_id'];
|
||||
|
||||
if (isset($data['blog_category_id'])) {
|
||||
$blog_path = $this->getBlogPathByArticle($article_id);
|
||||
}
|
||||
|
||||
//start add valide get-param
|
||||
if ($this->valide_get_param) {
|
||||
$valide_get_param_data = [];
|
||||
foreach($this->valide_get_param as $get_param) {
|
||||
if (isset($data[$get_param])) {
|
||||
$valide_get_param_data[$get_param] = $data[$get_param];
|
||||
/*
|
||||
* add x-robot-tag noindex
|
||||
* https://developers.google.com/search/reference/robots_meta_tag?hl=en
|
||||
*/
|
||||
$this->response->addHeader('X-Robots-Tag: noindex');
|
||||
}
|
||||
};
|
||||
}
|
||||
//end add valide get-param
|
||||
unset($data);
|
||||
$data['route'] = $route;
|
||||
|
||||
if ($blog_path && $this->config->get('config_seo_url_include_path')) {
|
||||
$data['blog_category_id'] = $blog_path;
|
||||
}
|
||||
|
||||
$data['article_id'] = $article_id;
|
||||
|
||||
if ($this->valide_get_param) {
|
||||
$data = array_merge($data, $valide_get_param_data);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
//blog
|
||||
|
||||
case 'service/service/info':
|
||||
if (isset($data['service_id'])) {
|
||||
$route = 'service/service/info';
|
||||
$service_id = $data['service_id'];
|
||||
|
||||
unset($data);
|
||||
$data['route'] = $route;
|
||||
$data['service_id'] = $service_id;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'product/category':
|
||||
if (isset($data['path'])) {
|
||||
$category = explode('_', $data['path']);
|
||||
$category = end($category);
|
||||
unset($data['information_id']);
|
||||
$data['path'] = $this->getPathByCategory($category);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'blog/article/review':
|
||||
return [$url, $data, $postfix];
|
||||
break;
|
||||
case 'product/product/review':
|
||||
return [$url, $data, $postfix];
|
||||
break;
|
||||
case 'product/product/review':
|
||||
return [$url, $data, $postfix];
|
||||
break;
|
||||
case 'information/information/info':
|
||||
case 'product/manufacturer/info':
|
||||
break;
|
||||
case 'information/information/agree':
|
||||
return [$url, $data, $postfix];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$queries = [];
|
||||
|
||||
$route = '';
|
||||
if (isset($data['route'])) {
|
||||
$route = $data['route'];
|
||||
unset($data['route']);
|
||||
}
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
|
||||
switch ($key) {
|
||||
case 'product_id':
|
||||
$product_id = (int)$value;
|
||||
$queries[] = 'product_id=' . $product_id;
|
||||
$postfix = true;
|
||||
unset($data[$key]);
|
||||
break;
|
||||
case 'manufacturer_id':
|
||||
$manufacturer_id = (int)$value;
|
||||
$queries[] = 'manufacturer_id=' . $manufacturer_id;
|
||||
$postfix = true;
|
||||
unset($data[$key]);
|
||||
break;
|
||||
case 'category_id':
|
||||
case 'information_id':
|
||||
$information_id = (int)$value;
|
||||
$queries[] = 'information_id=' . $information_id;
|
||||
$postfix = true;
|
||||
unset($data[$key]);
|
||||
break;
|
||||
//blog
|
||||
case 'blog_category_id':
|
||||
$blog_categories = explode('_', $value);
|
||||
foreach ($blog_categories as $blog_category_id) {
|
||||
$queries[] = 'blog_category_id=' . (int)$blog_category_id;
|
||||
}
|
||||
unset($data[$key]);
|
||||
break;
|
||||
case 'article_id':
|
||||
$article_id = (int)$value;
|
||||
$queries[] = 'article_id=' . $article_id;
|
||||
$postfix = true;
|
||||
unset($data[$key]);
|
||||
break;
|
||||
|
||||
//blog
|
||||
//services
|
||||
case 'service_id':
|
||||
$service_id = (int)$value;
|
||||
$queries[] = 'service_id=' . $service_id;
|
||||
$postfix = true;
|
||||
unset($data[$key]);
|
||||
break;
|
||||
//end services
|
||||
case 'path':
|
||||
$categories = explode('_', $value);
|
||||
foreach ($categories as $category_id) {
|
||||
$queries[] = 'category_id=' . (int)$category_id;
|
||||
}
|
||||
unset($data[$key]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($queries) && $route) {
|
||||
|
||||
$keyword = $this->getKeywordByQuery($route);
|
||||
//check url for route
|
||||
if($keyword !== null) {
|
||||
//common/home
|
||||
$url = '';
|
||||
if($keyword !== '')
|
||||
$url = '/' . rawurlencode($keyword);
|
||||
}
|
||||
//if not exist keyword for route & empty any keyword return route-param for native seo_url class
|
||||
$data['route'] = $route;
|
||||
|
||||
} else {
|
||||
|
||||
$rows = [];
|
||||
|
||||
foreach ($queries as $query) {
|
||||
$keyword = $this->getKeywordByQuery($query);
|
||||
if ($keyword)
|
||||
$rows[] = $keyword;
|
||||
}
|
||||
|
||||
if (!empty($rows) && (count($rows) == count($queries))) {
|
||||
foreach($rows as $row) {
|
||||
$url .= '/' . rawurlencode($row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [$url, $data, $postfix];
|
||||
}
|
||||
|
||||
private function getPath($categories, $category_id, $current_path = []) {
|
||||
|
||||
if(!$current_path)
|
||||
$current_path = [(int)$category_id];
|
||||
|
||||
$path = $current_path;
|
||||
|
||||
$parent_id = 0;
|
||||
|
||||
if(isset($categories[$category_id]['parent_id']))
|
||||
$parent_id = (int)$categories[$category_id]['parent_id'];
|
||||
|
||||
if($parent_id > 0) {
|
||||
$new_path = array_merge ([$parent_id] , $current_path);
|
||||
$path = $this->getPath($categories, $parent_id, $new_path);
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
|
||||
private function initHelpers() {
|
||||
// start category_tree
|
||||
if($this->config->get('config_seo_url_cache')){
|
||||
$this->cat_tree = $this->cache->get('seopro.cat_tree');
|
||||
}
|
||||
|
||||
if(!$this->cat_tree || empty($this->cat_tree)) {
|
||||
|
||||
$this->cat_tree = [];
|
||||
|
||||
$all_cat_query = $this->db->query("SELECT category_id, parent_id FROM " . DB_PREFIX . "category ORDER BY parent_id");
|
||||
|
||||
$allcats = [];
|
||||
$categories = [];
|
||||
|
||||
if($all_cat_query->num_rows) {
|
||||
$allcats = $all_cat_query->rows;
|
||||
};
|
||||
|
||||
foreach ($allcats as $category) {
|
||||
$categories[$category['category_id']]['parent_id'] = $category['parent_id'];
|
||||
};
|
||||
unset ($allcats);
|
||||
|
||||
foreach ($categories as $category_id => $category) {
|
||||
$path = $this->getPath($categories, $category_id);
|
||||
$this->cat_tree[$category_id]['path'] = $path;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
//end_category_tree
|
||||
|
||||
//keyword_data
|
||||
if ($this->config->get('config_seo_url_cache')) {
|
||||
|
||||
$this->keywords = $this->cache->get('seopro.keywords');
|
||||
$this->queries = $this->cache->get('seopro.queries');
|
||||
|
||||
if ((!$this->keywords || empty($this->keywords) || !$this->queries || empty($this->queries))) {
|
||||
|
||||
$sql_keyword = 'keyword';
|
||||
if ($this->config->get('config_seopro_lowercase'))
|
||||
$sql_keyword = 'LCASE(keyword) as '. $sql_keyword;
|
||||
|
||||
$sql = "SELECT " . $sql_keyword . ", query, store_id, language_id FROM " . DB_PREFIX . "seo_url WHERE 1";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
if($query->num_rows) {
|
||||
foreach($query->rows as $row) {
|
||||
$this->keywords[$row['query']][$row['store_id']][$row['language_id']] = $row['keyword'];
|
||||
$this->queries[$row['keyword']][$row['store_id']][$row['language_id']] = $row['query'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//end_keyword_data
|
||||
}
|
||||
|
||||
private function detectPostfix() {
|
||||
if($this->config->get('config_page_postfix') && isset($this->request->get['_route_'])) {
|
||||
$this->request->get['_route_'] = preg_replace('/' . $this->config->get('config_page_postfix') . '$/', '', (string)$this->request->get['_route_']);
|
||||
}
|
||||
}
|
||||
|
||||
private function addpostfix($url) {
|
||||
if($this->config->get('config_page_postfix')) {
|
||||
$url = rtrim($url, "/") . $this->config->get('config_page_postfix');
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
private function getQueryByKeyword($keyword, $language_id = null) {
|
||||
$query = null;
|
||||
$store_id = (int)$this->config->get('config_store_id');
|
||||
|
||||
if (!$language_id)
|
||||
$language_id = (int)$this->config->get('config_language_id');
|
||||
|
||||
if ($this->config->get('config_seo_url_cache')){
|
||||
if (isset($this->queries[$keyword][$store_id][$language_id]))
|
||||
$query = $this->queries[$keyword][$store_id][$language_id];
|
||||
} else {
|
||||
$_query = $this->db->query("SELECT query FROM " . DB_PREFIX . "seo_url WHERE keyword = '" . $this->db->escape(trim($keyword)) . "' AND store_id = '" . $store_id . "' AND language_id = '" . $language_id . "' LIMIT 1");
|
||||
$query = !empty($_query->row) ? (string)$_query->row['query'] : null;
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function getKeywordByQuery($query, $language_id = null) {
|
||||
|
||||
$keyword = null;
|
||||
$store_id = (int)$this->config->get('config_store_id');
|
||||
|
||||
if (!$language_id)
|
||||
$language_id = $this->config->get('config_language_id');
|
||||
|
||||
|
||||
if ($this->config->get('config_seo_url_cache')) {
|
||||
if (isset($this->keywords[$query][$store_id][$language_id]))
|
||||
$keyword = $this->keywords[$query][$store_id][$language_id];
|
||||
} else {
|
||||
|
||||
$sql_keyword = 'keyword';
|
||||
if ($this->config->get('config_seopro_lowercase'))
|
||||
$sql_keyword = 'LCASE(keyword) as '. $sql_keyword;
|
||||
|
||||
|
||||
$query = $this->db->query("SELECT " . $sql_keyword . " FROM " . DB_PREFIX . "seo_url WHERE query = '" . $this->db->escape($query) . "' AND store_id = '" . $store_id . "' AND language_id = '" . (int)$language_id . "' LIMIT 1");
|
||||
$keyword = !empty($query->row) ? (string)$query->row['keyword'] : null;
|
||||
|
||||
}
|
||||
|
||||
return $keyword;
|
||||
}
|
||||
|
||||
public function validate() {
|
||||
|
||||
// break redirect for php-cli-script
|
||||
if (php_sapi_name() === 'cli')
|
||||
return;
|
||||
|
||||
// fix flat link for xml feed
|
||||
if (isset($this->request->get['route'])) {
|
||||
$break_routes = [
|
||||
'error/not_found',
|
||||
'extension/feed/google_sitemap',
|
||||
'extension/feed/google_base',
|
||||
'extension/feed/sitemap_pro',
|
||||
'extension/feed/yandex_feed'
|
||||
];
|
||||
|
||||
if (in_array($this->request->get['route'], $break_routes))
|
||||
return;
|
||||
}
|
||||
|
||||
if (!empty($this->request->post))
|
||||
return;
|
||||
|
||||
if ($this->ajax) {
|
||||
$this->response->addHeader('X-Robots-Tag: noindex');
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($this->request->get['route']))
|
||||
$this->request->get['route'] = 'common/home';
|
||||
|
||||
|
||||
$uri = $this->request->server['REQUEST_URI'];
|
||||
$route = $this->request->get['route'];
|
||||
|
||||
// remove negative page number
|
||||
if (isset($this->request->get['page'])) {
|
||||
if((float)$this->request->get['page'] < 1) {
|
||||
unset($this->request->get['page']);
|
||||
};
|
||||
};
|
||||
|
||||
if ($_SERVER['HTTPS'] == true) {
|
||||
$host = substr($this->config->get('config_ssl'), 0, $this->strpos_offset('/', $this->config->get('config_ssl'), 3) + 1);
|
||||
} else {
|
||||
$host = substr($this->config->get('config_url'), 0, $this->strpos_offset('/', $this->config->get('config_url'), 3) + 1);
|
||||
}
|
||||
|
||||
if (!$this->config->get('config_seopro_addslash')) {
|
||||
if ($uri == '/') {
|
||||
$host = rtrim($host, '/');
|
||||
}
|
||||
}
|
||||
|
||||
$url = str_replace('&', '&', $host . ltrim($uri, '/'));
|
||||
$seo = str_replace('&', '&', $this->url->link($route, $this->getQueryString(array('_route_', 'route')), $_SERVER['HTTPS']));
|
||||
|
||||
|
||||
if (rawurldecode($url) != rawurldecode($seo)) {
|
||||
$this->response->redirect($seo, 301);
|
||||
}
|
||||
}
|
||||
|
||||
private function detectAjax () {
|
||||
if (isset($this->request->server['HTTP_X_REQUESTED_WITH']) && strtolower($this->request->server['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
|
||||
$this->ajax = true;
|
||||
}
|
||||
|
||||
private function detectLanguage() {
|
||||
|
||||
if ($this->ajax)
|
||||
return;
|
||||
|
||||
$request_language_id = null;
|
||||
$request_language_code = '';
|
||||
$active_language_id = $this->config->get('config_language_id');
|
||||
|
||||
if (isset($this->request->get['_route_'])) {
|
||||
$parts = $parts = explode('/', $this->request->get['_route_']);
|
||||
$keyword = end($parts);
|
||||
} else {
|
||||
$keyword = '';
|
||||
}
|
||||
|
||||
if ($keyword || $this->request->server['REQUEST_URI'] == '/') {
|
||||
$query = $this->db->query("SELECT language_id FROM " . DB_PREFIX . "seo_url WHERE keyword = '" . $this->db->escape(trim($keyword)) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' LIMIT 1");
|
||||
if ($query->row) {
|
||||
$request_language_id = (int)$query->row['language_id'];
|
||||
|
||||
$query = $this->db->query("SELECT code FROM " . DB_PREFIX . "language WHERE language_id = '" . (int)$request_language_id . "' AND status = '1' LIMIT 1");
|
||||
|
||||
if ($query->row) {
|
||||
$request_language_code = $query->row['code'];
|
||||
$this->session->data['language'] = $request_language_code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->session->data['language'])) {
|
||||
$query = $this->db->query("SELECT language_id FROM " . DB_PREFIX . "language WHERE code = '" . (int)$this->session->data['language'] . "' AND status = '1' LIMIT 1");
|
||||
if ($query->num_rows) {
|
||||
$active_language_id = (int)$query->row['language_id'];
|
||||
}
|
||||
}
|
||||
|
||||
if($request_language_id && $request_language_code && $active_language_id != $request_language_id) {
|
||||
$language = new Language($request_language_code);
|
||||
$language->load($request_language_code);
|
||||
$this->registry->set('language', $language);
|
||||
$this->config->set('config_language_id', $request_language_id);
|
||||
$this->registry->set('language', $language);
|
||||
}
|
||||
}
|
||||
|
||||
private function getCategoryByProduct($product_id) {
|
||||
|
||||
if ((int)$product_id < 1)
|
||||
return false;
|
||||
|
||||
if ($this->config->get('config_seo_url_cache')) {
|
||||
$this->product_categories = $this->cache->get('seopro.product_categories');
|
||||
if(isset($this->product_categories[$product_id]))
|
||||
return $this->product_categories[$product_id];
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "' ORDER BY main_category DESC LIMIT 1");
|
||||
$category_id = $this->getPathByCategory($query->num_rows ? (int)$query->row['category_id'] : 0);
|
||||
|
||||
if ($this->config->get('config_seo_url_cache')) {
|
||||
$this->product_categories[$product_id] = $category_id;
|
||||
}
|
||||
|
||||
return $category_id;
|
||||
}
|
||||
|
||||
private function getPathByCategory($category_id) {
|
||||
|
||||
$path = '';
|
||||
|
||||
if ((int)$category_id < 1 && !isset($this->cat_tree[$category_id]))
|
||||
return false;
|
||||
|
||||
if (!empty($this->cat_tree[$category_id]['path']) && is_array($this->cat_tree[$category_id]['path'])) {
|
||||
$path = implode('_', $this->cat_tree[$category_id]['path']);
|
||||
}
|
||||
|
||||
return $path;
|
||||
|
||||
}
|
||||
|
||||
private function getBlogPathByArticle($article_id) {
|
||||
|
||||
if ($article_id < 1)
|
||||
return false;
|
||||
|
||||
$query = $this->db->query("SELECT blog_category_id FROM " . DB_PREFIX . "article_to_blog_category WHERE article_id = '" . (int)$article_id . "' ORDER BY main_blog_category DESC LIMIT 1");
|
||||
$blog_category_path = $this->getBlogPathByCategory($query->num_rows ? (int)$query->row['blog_category_id'] : 0);
|
||||
|
||||
return $blog_category_path;
|
||||
}
|
||||
|
||||
private function getBlogPathByCategory($blog_category_id) {
|
||||
$blog_category_id = (int)$blog_category_id;
|
||||
if ($blog_category_id < 1)
|
||||
return false;
|
||||
|
||||
static $blog_path = [];
|
||||
$cache = 'seopro.blog_category.seopath';
|
||||
|
||||
if (!is_array($blog_path)) {
|
||||
if ($this->config->get('config_seo_url_cache'))
|
||||
$blog_path = $this->cache->get($cache);
|
||||
if (!is_array($blog_path))
|
||||
$blog_path = [];
|
||||
}
|
||||
|
||||
if (!isset($blog_path[$blog_category_id])) {
|
||||
$max_level = 10;
|
||||
$sql = "SELECT CONCAT_WS('_'";
|
||||
for ($i = $max_level-1; $i >= 0; --$i) {
|
||||
$sql .= ",t$i.blog_category_id";
|
||||
}
|
||||
$sql .= ") AS path FROM " . DB_PREFIX . "blog_category t0";
|
||||
for ($i = 1; $i < $max_level; ++$i) {
|
||||
$sql .= " LEFT JOIN " . DB_PREFIX . "blog_category t$i ON (t$i.blog_category_id = t" . ($i-1) . ".parent_id)";
|
||||
}
|
||||
$sql .= " WHERE t0.blog_category_id = '" . $blog_category_id . "'";
|
||||
$query = $this->db->query($sql);
|
||||
$blog_path[$blog_category_id] = $query->num_rows ? $query->row['path'] : false;
|
||||
|
||||
if ($this->config->get('config_seo_url_cache'))
|
||||
$this->cache->set($cache, $blog_path);
|
||||
}
|
||||
|
||||
return $blog_path[$blog_category_id];
|
||||
}
|
||||
|
||||
private function strpos_offset($needle, $haystack, $occurrence) {
|
||||
// explode the haystack
|
||||
$arr = explode($needle, $haystack);
|
||||
// check the needle is not out of bounds
|
||||
switch($occurrence) {
|
||||
case $occurrence == 0:
|
||||
return false;
|
||||
case $occurrence > max(array_keys($arr)):
|
||||
return false;
|
||||
default:
|
||||
return strlen(implode($needle, array_slice($arr, 0, $occurrence)));
|
||||
}
|
||||
}
|
||||
|
||||
private function getQueryString($exclude = []) {
|
||||
if (!is_array($exclude))
|
||||
$exclude = [];
|
||||
|
||||
return urldecode(http_build_query(array_diff_key($this->request->get, array_flip($exclude))));
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
|
||||
if(!$this->config->get('config_seo_pro'))
|
||||
return;
|
||||
|
||||
if ($this->config->get('config_seo_url_cache')){
|
||||
$this->cache->set('seopro.keywords', $this->keywords);
|
||||
$this->cache->set('seopro.queries', $this->queries);
|
||||
$this->cache->set('seopro.cat_tree', $this->cat_tree);
|
||||
$this->cache->set('seopro.product_categories', $this->product_categories);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* Session class
|
||||
*/
|
||||
class Session {
|
||||
protected $adaptor;
|
||||
protected $session_id;
|
||||
public $data = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $adaptor
|
||||
* @param object $registry
|
||||
*/
|
||||
public function __construct($adaptor, $registry = '') {
|
||||
$class = 'Session\\' . $adaptor;
|
||||
|
||||
if (class_exists($class)) {
|
||||
if ($registry) {
|
||||
$this->adaptor = new $class($registry);
|
||||
} else {
|
||||
$this->adaptor = new $class();
|
||||
}
|
||||
|
||||
register_shutdown_function(array($this, 'close'));
|
||||
} else {
|
||||
trigger_error('Error: Could not load cache adaptor ' . $adaptor . ' session!');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->session_id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $session_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function start($session_id = '') {
|
||||
if (!$session_id) {
|
||||
if (function_exists('random_bytes')) {
|
||||
$session_id = substr(bin2hex(random_bytes(26)), 0, 26);
|
||||
} else {
|
||||
$session_id = substr(bin2hex(openssl_random_pseudo_bytes(26)), 0, 26);
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match('/^[a-zA-Z0-9,\-]{22,52}$/', $session_id)) {
|
||||
$this->session_id = $session_id;
|
||||
} else {
|
||||
exit('Error: Invalid session ID!');
|
||||
}
|
||||
|
||||
$this->data = $this->adaptor->read($session_id);
|
||||
|
||||
return $session_id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function close() {
|
||||
$this->adaptor->write($this->session_id, $this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function destroy() {
|
||||
$this->adaptor->destroy($this->session_id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace Session;
|
||||
|
||||
final class DB {
|
||||
public $maxlifetime;
|
||||
|
||||
public function __construct($registry) {
|
||||
$this->db = $registry->get('db');
|
||||
|
||||
$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` > '" . $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() + (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) . "'");
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace Session;
|
||||
class File {
|
||||
private $directory;
|
||||
|
||||
public function read($session_id) {
|
||||
$file = DIR_SESSION . '/sess_' . basename($session_id);
|
||||
|
||||
if (is_file($file)) {
|
||||
$handle = fopen($file, 'r');
|
||||
|
||||
flock($handle, LOCK_SH);
|
||||
|
||||
$data = fread($handle, filesize($file));
|
||||
|
||||
flock($handle, LOCK_UN);
|
||||
|
||||
fclose($handle);
|
||||
|
||||
return unserialize($data);
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
public function write($session_id, $data) {
|
||||
$file = DIR_SESSION . '/sess_' . basename($session_id);
|
||||
|
||||
$handle = fopen($file, 'w');
|
||||
|
||||
flock($handle, LOCK_EX);
|
||||
|
||||
fwrite($handle, serialize($data));
|
||||
|
||||
fflush($handle);
|
||||
|
||||
flock($handle, LOCK_UN);
|
||||
|
||||
fclose($handle);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function destroy($session_id) {
|
||||
$file = DIR_SESSION . '/sess_' . basename($session_id);
|
||||
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
if (ini_get('session.gc_divisor')) {
|
||||
$gc_divisor = ini_get('session.gc_divisor');
|
||||
} else {
|
||||
$gc_divisor = 1;
|
||||
}
|
||||
|
||||
if (ini_get('session.gc_probability')) {
|
||||
$gc_probability = ini_get('session.gc_probability');
|
||||
} else {
|
||||
$gc_probability = 1;
|
||||
}
|
||||
|
||||
if ((rand() % $gc_divisor) < $gc_probability) {
|
||||
$expire = time() - ini_get('session.gc_maxlifetime');
|
||||
|
||||
$files = glob(DIR_SESSION . '/sess_*');
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (filemtime($file) < $expire) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* Template class
|
||||
*/
|
||||
class Template {
|
||||
private $adaptor;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $adaptor
|
||||
*
|
||||
*/
|
||||
public function __construct($adaptor) {
|
||||
$class = 'Template\\' . $adaptor;
|
||||
|
||||
if (class_exists($class)) {
|
||||
$this->adaptor = new $class();
|
||||
} else {
|
||||
throw new \Exception('Error: Could not load template adaptor ' . $adaptor . '!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function set($key, $value) {
|
||||
$this->adaptor->set($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $template
|
||||
* @param bool $cache
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render($template, $cache = false) {
|
||||
return $this->adaptor->render($template, $cache);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace Template;
|
||||
final class Template {
|
||||
private $data = array();
|
||||
|
||||
public function set($key, $value) {
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
|
||||
public function render($template) {
|
||||
$file = DIR_TEMPLATE . $template . '.tpl';
|
||||
|
||||
if (is_file($file)) {
|
||||
extract($this->data);
|
||||
|
||||
ob_start();
|
||||
|
||||
require(modification($file));
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
throw new \Exception('Error: Could not load template ' . $file . '!');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Template;
|
||||
final class Twig {
|
||||
private $data = array();
|
||||
|
||||
public function set($key, $value) {
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
|
||||
public function render($filename, $code = '') {
|
||||
if (!$code) {
|
||||
$file = DIR_TEMPLATE . $filename . '.twig';
|
||||
|
||||
if (defined('DIR_CATALOG') && is_file(DIR_MODIFICATION . 'admin/view/template/' . $filename . '.twig')) {
|
||||
$code = file_get_contents(DIR_MODIFICATION . 'admin/view/template/' . $filename . '.twig');
|
||||
} elseif (is_file(DIR_MODIFICATION . 'store/view/theme/' . $filename . '.twig')) {
|
||||
$code = file_get_contents(DIR_MODIFICATION . 'store/view/theme/' . $filename . '.twig');
|
||||
} elseif (is_file($file)) {
|
||||
$code = file_get_contents($file);
|
||||
} else {
|
||||
throw new \Exception('Error: Could not load template ' . $file . '!');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// initialize Twig environment
|
||||
$config = array(
|
||||
'autoescape' => false,
|
||||
'debug' => false,
|
||||
'auto_reload' => true,
|
||||
'cache' => DIR_CACHE . 'template/'
|
||||
);
|
||||
|
||||
try {
|
||||
$loader1 = new \Twig\Loader\ArrayLoader(array($filename . '.twig' => $code));
|
||||
$loader2 = new \Twig\Loader\FilesystemLoader(array(DIR_TEMPLATE));
|
||||
$loader = new \Twig\Loader\ChainLoader(array($loader1, $loader2));
|
||||
|
||||
$twig = new \Twig\Environment($loader, $config);
|
||||
|
||||
return $twig->render($filename . '.twig', $this->data);
|
||||
} catch (Exception $e) {
|
||||
trigger_error('Error: Could not load template ' . $filename . '!');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* @package OpenCart
|
||||
* @author Daniel Kerr
|
||||
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
||||
* @license https://opensource.org/licenses/GPL-3.0
|
||||
* @link https://www.opencart.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* URL class
|
||||
*/
|
||||
class Url {
|
||||
private $url;
|
||||
private $ssl;
|
||||
private $rewrite = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $ssl
|
||||
*
|
||||
*/
|
||||
public function __construct($url, $ssl = '') {
|
||||
$this->url = $url;
|
||||
$this->ssl = $ssl;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param object $rewrite
|
||||
*/
|
||||
public function addRewrite($rewrite) {
|
||||
$this->rewrite[] = $rewrite;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $route
|
||||
* @param mixed $args
|
||||
* @param bool $secure
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function link($route, $args = '', $secure = false) {
|
||||
if ($this->ssl && $secure) {
|
||||
$url = $this->ssl . 'index.php?route=' . $route;
|
||||
} else {
|
||||
$url = $this->url . 'index.php?route=' . $route;
|
||||
}
|
||||
|
||||
if ($args) {
|
||||
if (is_array($args)) {
|
||||
$url .= '&' . http_build_query($args);
|
||||
} else {
|
||||
$url .= str_replace('&', '&', '&' . ltrim($args, '&'));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->rewrite as $rewrite) {
|
||||
$url = $rewrite->rewrite($url);
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user