Skip to content

Commit

Permalink
OkayCMS 2.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
OkayCMS committed Jun 7, 2019
1 parent 1a1db59 commit 5f37f69
Show file tree
Hide file tree
Showing 81 changed files with 3,573 additions and 10,921 deletions.
21 changes: 11 additions & 10 deletions 1DB_changes/okay_clean.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ CREATE TABLE `ok_banners` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`group_id` varchar(32) NOT NULL DEFAULT '',
`name` varchar(255) NOT NULL DEFAULT '',
`description` text NOT NULL,
`position` int(11) NOT NULL DEFAULT '0',
`visible` tinyint(1) NOT NULL DEFAULT '1',
`show_all_pages` tinyint(1) NOT NULL DEFAULT '0',
Expand All @@ -22,8 +21,8 @@ CREATE TABLE `ok_banners` (
KEY `brands` (`brands`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `ok_banners` (`id`, `group_id`, `name`, `description`, `position`, `visible`, `show_all_pages`, `categories`, `pages`, `brands`) VALUES
(1, 'group1', 'Главный баннер', '', 1, 1, 0, '0', '1', '0');
INSERT INTO `ok_banners` (`id`, `group_id`, `name`, `position`, `visible`, `show_all_pages`, `categories`, `pages`, `brands`) VALUES
(1, 'group1', 'Главный баннер', 1, 1, 0, '0', '1', '0');

DROP TABLE IF EXISTS `ok_banners_images`;
CREATE TABLE `ok_banners_images` (
Expand Down Expand Up @@ -3885,15 +3884,16 @@ CREATE TABLE `ok_orders_status` (
`is_close` tinyint(1) NOT NULL DEFAULT '0',
`color` varchar(6) NOT NULL DEFAULT 'ffffff',
`position` int(11) NOT NULL DEFAULT '0',
`status_1c` enum('not_use', 'new','accepted','to_delete') NULL DEFAULT 'not_use',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `ok_orders_status` (`id`, `name`, `is_close`, `color`, `position`) VALUES
(1, 'Новые', 0, '2015eb', 1),
(2, 'Приняты', 1, '2ccc1a', 2),
(3, 'У курьера', 1, 'ffd000', 3),
(4, 'Выполнены', 1, 'c400ff', 4),
(5, 'Удалены', 0, 'eb1212', 5);
INSERT INTO `ok_orders_status` (`id`, `name`, `is_close`, `color`, `position`, `status_1c`) VALUES
(1, 'Новые', 0, '2015eb', 1, 'new'),
(2, 'Приняты', 1, '2ccc1a', 2, 'accepted'),
(3, 'У курьера', 1, 'ffd000', 3, 'not_use'),
(4, 'Выполнены', 1, 'c400ff', 4, 'not_use'),
(5, 'Удалены', 0, 'eb1212', 5, 'to_delete');

DROP TABLE IF EXISTS `ok_pages`;
CREATE TABLE `ok_pages` (
Expand Down Expand Up @@ -5765,7 +5765,8 @@ INSERT INTO `ok_settings` (`setting_id`, `param`, `value`) VALUES
(161, 'max_filter_filter', '1'),
(162, 'max_filter_features_values', '1'),
(163, 'max_filter_features', '1'),
(164, 'max_filter_depth', '1');
(164, 'max_filter_depth', '1'),
(200, 'recaptcha_scores', 'a:3:{s:7:\"product\";d:0.5;s:4:\"cart\";d:0.69999999999999996;s:5:\"other\";d:0.20000000000000001;}');

DROP TABLE IF EXISTS `ok_settings_lang`;
CREATE TABLE `ok_settings_lang` (
Expand Down
8 changes: 8 additions & 0 deletions 1DB_changes/update_2.3.3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ALTER TABLE `ok_banners` DROP `description`;

ALTER TABLE `ok_settings` ADD UNIQUE `param` (`param`);

INSERT INTO `ok_settings` (`param`, `value`) VALUES
('recaptcha_scores', 'a:3:{s:7:\"product\";d:0.5;s:4:\"cart\";d:0.69999999999999996;s:5:\"other\";d:0.20000000000000001;}');

ALTER TABLE `ok_orders_status` ADD `status_1c` enum('new','accepted','to_delete', 'not_use') NULL DEFAULT 'not_use';
77 changes: 64 additions & 13 deletions api/Banners.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,76 @@ public function delete_banners_image($id) {
}

/*Выбираем все группы баннеров*/
public function get_banners($filter = array()) {
$visible_filter = '';
$banners = array();

if(isset($filter['visible'])) {
$visible_filter = $this->db->placehold('AND visible = ?', intval($filter['visible']));
public function get_banners($filter = array(), $count = false) {
$limit = 100; // По умолчанию
$page = 1;
$joins = '';
$where = '1';
$group_by = '';
$order = 'b.position DESC';
$select = "b.*";
if ($count === true) {
$select = "COUNT(DISTINCT b.id) as count";
}

if(isset($filter['limit'])) {
$limit = max(1, intval($filter['limit']));
}

if(isset($filter['page'])) {
$page = max(1, intval($filter['page']));
}

$sql_limit = $this->db->placehold(' LIMIT ?, ? ', ($page-1)*$limit, $limit);

$query = "SELECT * FROM __banners WHERE 1 $visible_filter ORDER BY position";

if (isset($filter['visible'])) {
$where .= $this->db->placehold(' AND visible = ?', intval($filter['visible']));
}

// При подсчете нам эти переменные не нужны
if ($count === true) {
$order = '';
$group_by = '';
$sql_limit = '';
}

if (!empty($order)) {
$order = "ORDER BY $order";
}

// При подсчете нам эти переменные не нужны
if ($count === true) {
$order = '';
$group_by = '';
$sql_limit = '';
}

$query = $this->db->placehold("SELECT $select
FROM __banners b
$joins
WHERE
$where
$group_by
$order
$sql_limit
");

$this->db->query($query);

foreach($this->db->results() as $banner) {
$banners[$banner->id] = $banner;
if ($count === true) {
return $this->db->result('count');
} else {
$banners = array();
foreach($this->db->results() as $banner) {
$banners[$banner->id] = $banner;
}
return $banners;
}

return $banners;
}

public function count_banners($filter = array()) {
return $this->get_banners($filter, true);
}

/*Выбираем определенную группу баннеров*/
public function get_banner($id, $visible = false, $show_filter_array = array()) {
if (empty($id)) {
Expand Down
25 changes: 17 additions & 8 deletions api/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
class Config {

/*Версия системы*/
public $version = '2.3.2';
public $version = '2.3.3';
/*Тип системы*/
public $version_type = 'pro';

/*Файл для хранения настроек*/
public $config_file = 'config/config.php';
public $config_develop_file = 'config/config.local.php';
public $config_local_file = 'config/config.local.php';

private $vars = array();
private $local_vars = array();

/*
* В конструкторе записываем настройки файла в переменные этого класса
Expand All @@ -33,10 +34,10 @@ public function __construct() {
}

/*Заменяем настройки, если есть локальный конфиг*/
if (file_exists(dirname(dirname(__FILE__)).'/'.$this->config_develop_file)) {
$ini = parse_ini_file(dirname(dirname(__FILE__)) . '/' . $this->config_develop_file);
if (file_exists(dirname(dirname(__FILE__)).'/'.$this->config_local_file)) {
$ini = parse_ini_file(dirname(dirname(__FILE__)) . '/' . $this->config_local_file);
foreach ($ini as $var => $value) {
$this->vars[$var] = $value;
$this->local_vars[$var] = $this->vars[$var] = $value;
}
}

Expand Down Expand Up @@ -99,10 +100,18 @@ public function __get($name) {

/*Запись данных в конфиг*/
public function __set($name, $value) {
if(isset($this->vars[$name])) {
$conf = file_get_contents(dirname(dirname(__FILE__)).'/'.$this->config_file);
if(isset($this->vars[$name]) || isset($this->local_vars[$name])) {

// Определяем в каком файле конфига переопределять значения
if (isset($this->local_vars[$name])) {
$config_file = $this->config_local_file;
} else {
$config_file = $this->config_file;
}

$conf = file_get_contents(dirname(dirname(__FILE__)).'/'.$config_file);
$conf = preg_replace("/".$name."\s*=.*\n/i", $name.' = '.$value."\r\n", $conf);
$cf = fopen(dirname(dirname(__FILE__)).'/'.$this->config_file, 'w');
$cf = fopen(dirname(dirname(__FILE__)).'/'.$config_file, 'w');
fwrite($cf, $conf);
fclose($cf);
$this->vars[$name] = $value;
Expand Down
12 changes: 10 additions & 2 deletions api/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public function connect() {
// Выводим сообщение, в случае ошибки
if($this->mysqli->connect_error)
{
trigger_error("Could not connect to the database: ".$this->mysqli->connect_error, E_USER_WARNING);
ini_set('display_errors', 'on');
trigger_error("Could not connect to the database: ".$this->mysqli->connect_error, E_USER_ERROR);
return false;
}
// Или настраиваем соединение
Expand Down Expand Up @@ -66,7 +67,14 @@ public function connect() {
$l->domains = explode(',', $l->domains);
$h = getenv("HTTP_HOST");
if(substr($h, 0, 4) == 'www.') {$h = substr($h, 4);}
if((!in_array($h, $l->domains) || (strtotime($l->expiration)<time() && $l->expiration!='*'))) {
$sv = false;$da = explode('.', $h);$it = count($da);
for ($i=1;$i<=$it;$i++) {
unset($da[0]);$da = array_values($da);$d = '*.'.implode('.', $da);
if (in_array($d, $l->domains) || in_array('*.'.$h, $l->domains)) {
$sv = true;break;
}
}
if(((!in_array($h, $l->domains) && !$sv) || (strtotime($l->expiration)<time() && $l->expiration!='*')) && strtolower(php_sapi_name()) != 'cli') {
$this->rev = true;
}
return $this->mysqli;
Expand Down
53 changes: 36 additions & 17 deletions api/FeaturesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,17 @@ public function get_features_values($filter = array(), $count = false) {
}

if (isset($filter['yandex'])) {
$yandex_filter = $this->db->placehold("AND `f`.`yandex`=?", (int)$filter['yandex']);
$yandex_filter = $this->db->placehold("AND `f`.`yandex`=? AND `pf`.`product_id` IN (
SELECT
distinct(p.id)
FROM ok_variants v
LEFT JOIN ok_products p ON v.product_id=p.id
WHERE
p.visible
AND v.feed = 1
AND (v.stock >0 OR v.stock is NULL)
AND v.price >0
)", (int)$filter['yandex']);
}

if(isset($filter['id'])) {
Expand Down Expand Up @@ -192,11 +202,10 @@ public function get_features_values($filter = array(), $count = false) {
$sql_limit = "";
} else {
$select = $this->db->placehold("
MAX(`fv`.`id`) AS `id`,
MAX(`fv`.`feature_id`) AS `feature_id`,
MAX(`fv`.`position`) AS `position`,
`fv`.`id`,
`fv`.`feature_id`,
`fv`.`position`,
count(`pf`.`product_id`) AS `count`,
MAX(`f`.`id`) AS `feature_id`,
MAX(`f`.`auto_name_id`) AS `auto_name_id`,
MAX(`f`.`auto_value_id`) AS `auto_value_id`,
MAX(`f`.`url`) AS `url`,
Expand Down Expand Up @@ -388,20 +397,25 @@ public function add_feature_value($feature_value) {

$feature_value->value = trim($feature_value->value);

if (!$feature_value->translit) {
if (empty($feature_value->translit)) {
$feature_value->translit = $this->translit_alpha($feature_value->value);
}
$feature_value->translit = strtr(strtolower(trim($feature_value->translit)), $this->spec_pairs);

$result = $this->languages->get_description($feature_value, 'feature_value');
$result = $this->languages->get_description($feature_value, 'feature_value', false);

if($this->db->query("INSERT INTO `__features_values` SET ?%", $feature_value)) {
if ($this->db->query("INSERT INTO `__features_values` SET ?%", $feature_value)) {
$id = $this->db->insert_id();
if (empty($feature_value->position)) {
$this->db->query("UPDATE `__features_values` SET `position`=`id` WHERE `id`=?", $id);
}

if(!empty($result->description)) {
if (!empty($result->description)) {

if (!empty($feature_value->feature_id)) {
$result->description->feature_id = $feature_value->feature_id;
}

$this->languages->action_description($id, $result->description, 'feature_value');
}
return $id;
Expand All @@ -418,7 +432,7 @@ public function update_feature_value($id, $feature_value) {
$feature_value->value = trim($feature_value->value);
}

if (!$feature_value->translit && $feature_value->value) {
if (empty($feature_value->translit) && !empty($feature_value->value)) {
$feature_value->translit = $this->translit_alpha($feature_value->value);
}

Expand All @@ -428,15 +442,20 @@ public function update_feature_value($id, $feature_value) {

$result = $this->languages->get_description($feature_value, 'feature_value');

$query = $this->db->placehold("UPDATE `__features_values` SET ?% WHERE `id`=? LIMIT 1", $feature_value, (int)$id);
if($this->db->query($query)) {
if(!empty($result->description)) {
$this->languages->action_description($id, $result->description, 'feature_value', $this->languages->lang_id());
if (!empty((array)$feature_value)) {
$query = $this->db->placehold("UPDATE `__features_values` SET ?% WHERE `id`=? LIMIT 1", $feature_value, (int)$id);
$this->db->query($query);
}

if (!empty($result->description)) {

if (!empty($feature_value->feature_id)) {
$result->description->feature_id = $feature_value->feature_id;
}
return $id;
} else {
return false;

$this->languages->action_description($id, $result->description, 'feature_value', $this->languages->lang_id());
}
return $id;
}

/*добавление значения свойства товара*/
Expand Down
6 changes: 3 additions & 3 deletions api/Languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function get_fields($object = '') {
$fields['orders_labels'] = array('name');
$fields['orders_status'] = array('name');
$fields['menu_items'] = array('name');
$fields['features_values'] = array('value', 'translit', 'feature_id');
$fields['features_values'] = array('value', 'translit');
$fields['seo_filter_patterns'] = array('h1', 'title', 'keywords', 'meta_description', 'description');
$fields['features_aliases'] = array('name');
$fields['features_aliases_values'] = array('value');
Expand Down Expand Up @@ -300,7 +300,7 @@ public function action_data($object_id, $data, $object) {
}

/*Выборка мультиязычных данных*/
public function get_description($data, $object) {
public function get_description($data, $object, $clear = true) {
if(!in_array($object, array_keys($this->tables)) || empty($this->languages)) {
return false;
}
Expand All @@ -313,7 +313,7 @@ public function get_description($data, $object) {
if (isset($data->$f)) {
$description->$f = $data->$f;
}
if($this->first_language->id != $this->lang_id()) {
if ($this->first_language->id != $this->lang_id() && $clear === true) {
unset($data->$f);
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/Managers.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Managers extends Okay {
'users', 'groups', 'coupons', 'pages', 'blog', 'comments', 'feedbacks', 'import', 'export',
'stats', 'design', 'settings', 'currency', 'delivery', 'payment', 'managers', 'license', 'languages',
'banners', 'callbacks','robots', 'seo_patterns', 'support', 'subscribes', 'menu', 'seo_filter_patterns',
'settings_counter', 'features_aliases'
'settings_counter', 'features_aliases', 'integration_1c'

);

Expand Down
8 changes: 6 additions & 2 deletions api/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function delete_currency($id) {
}

/*Конвертация валюты в определнный формат*/
public function convert($price, $currency_id = null, $format = true) {
public function convert($price, $currency_id = null, $format = true, $revers = false) {
if(isset($currency_id)) {
if(is_numeric($currency_id)) {
$currency = $this->get_currency((integer)$currency_id);
Expand All @@ -146,7 +146,11 @@ public function convert($price, $currency_id = null, $format = true) {
$result = $price;
if(!empty($currency)) {
// Умножим на курс валюты
$result = $result*$currency->rate_from/$currency->rate_to;
if ($revers === true) {
$result = $result*$currency->rate_to/$currency->rate_from;
} else {
$result = $result*$currency->rate_from/$currency->rate_to;
}

// Точность отображения, знаков после запятой
$precision = isset($currency->cents)?$currency->cents:2;
Expand Down
Loading

0 comments on commit 5f37f69

Please sign in to comment.