From 0a0bccdc764faf7f44755da825533ccc6794a704 Mon Sep 17 00:00:00 2001 From: Remigijus Kiminas Date: Tue, 20 Dec 2022 04:22:00 -0500 Subject: [PATCH] Multi theme support --- .../parts/design_configuration.tpl.php | 19 ++- .../tpl/lhstatistic/userstats.tpl.php | 6 +- .../defaulttheme/tpl/lhtheme/default.tpl.php | 6 +- .../lib/core/lhdepartament/lhdepartament.php | 4 +- lhc_web/modules/lhchat/start.php | 111 +++++++++++++----- lhc_web/modules/lhtheme/default.php | 6 +- lhc_web/modules/lhwidgetrestapi/settings.php | 37 ++++-- 7 files changed, 138 insertions(+), 51 deletions(-) diff --git a/lhc_web/design/defaulttheme/tpl/lhdepartment/parts/design_configuration.tpl.php b/lhc_web/design/defaulttheme/tpl/lhdepartment/parts/design_configuration.tpl.php index d2c1074558..c7cdc7a09b 100644 --- a/lhc_web/design/defaulttheme/tpl/lhdepartment/parts/design_configuration.tpl.php +++ b/lhc_web/design/defaulttheme/tpl/lhdepartment/parts/design_configuration.tpl.php @@ -10,9 +10,9 @@
'theme_ind', - 'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Select theme'), - 'selected_id' => isset($departament->bot_configuration_array['theme_ind']) ? $departament->bot_configuration_array['theme_ind'] : 0, + 'input_name' => 'theme_ind[]', + 'multiple' => true, + 'selected_id' => isset($departament->bot_configuration_array['theme_ind']) ? explode(',',$departament->bot_configuration_array['theme_ind']) : 0, 'css_class' => 'form-control form-control-sm', 'display_name' => 'name', 'list_function' => 'erLhAbstractModelWidgetTheme::getList' @@ -20,11 +20,20 @@
- - bot_configuration_array['theme_default']) && $departament->bot_configuration_array['theme_default'] > 0) ? print htmlspecialchars(erLhAbstractModelWidgetTheme::fetch($departament->bot_configuration_array['theme_default'])) : print 'n/a';?> + + bot_configuration_array['theme_default']) as $themeDefault) : if ((int)$themeDefault > 0) : ?> + + +

getTranslation('department/edit','This theme is set from');?> getTranslation('department/edit','Default theme');?> getTranslation('department/edit','section and checking As default department theme.');?>

- - current_value > 0 ? print htmlspecialchars(erLhAbstractModelWidgetTheme::fetch(erLhcoreClassModelChatConfig::fetch('default_theme_id')->current_value)) : print 'n/a';?> + - + + current_value) as $themeDefault) : if ((int)$themeDefault > 0) : ?> + + +

getTranslation('department/edit','If you are using only');?> Default theme getTranslation('department/edit','option and you have more than one server you might get inconsistent theme pickup. Apply');?> getTranslation('department/edit','Default theme');?> getTranslation('department/edit','to department as default or choose individual theme.');?>

\ No newline at end of file diff --git a/lhc_web/design/defaulttheme/tpl/lhstatistic/userstats.tpl.php b/lhc_web/design/defaulttheme/tpl/lhstatistic/userstats.tpl.php index d5624da263..136e6a4042 100644 --- a/lhc_web/design/defaulttheme/tpl/lhstatistic/userstats.tpl.php +++ b/lhc_web/design/defaulttheme/tpl/lhstatistic/userstats.tpl.php @@ -125,8 +125,10 @@ - - getTranslation('statistic/departmentstats','Yes');?> + + + homeaccount_balancegetTranslation('statistic/departmentstats','Yes');?> + getTranslation('statistic/departmentstats','No');?> diff --git a/lhc_web/design/defaulttheme/tpl/lhtheme/default.tpl.php b/lhc_web/design/defaulttheme/tpl/lhtheme/default.tpl.php index dba3c68857..f3a5fa08e3 100644 --- a/lhc_web/design/defaulttheme/tpl/lhtheme/default.tpl.php +++ b/lhc_web/design/defaulttheme/tpl/lhtheme/default.tpl.php @@ -9,11 +9,11 @@
- - false, 'sort' => '`name` ASC')) as $theme) : ?> - +
diff --git a/lhc_web/lib/core/lhdepartament/lhdepartament.php b/lhc_web/lib/core/lhdepartament/lhdepartament.php index c01f99eff5..b1248bfaac 100644 --- a/lhc_web/lib/core/lhdepartament/lhdepartament.php +++ b/lhc_web/lib/core/lhdepartament/lhdepartament.php @@ -163,7 +163,7 @@ public static function validateDepartment(erLhcoreClassModelDepartament & $depar ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1) ), 'theme_ind' => new ezcInputFormDefinitionElement( - ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1) + ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1), FILTER_REQUIRE_ARRAY ), 'bot_only_offline' => new ezcInputFormDefinitionElement( ezcInputFormDefinitionElement::OPTIONAL, 'boolean' @@ -586,7 +586,7 @@ public static function validateDepartment(erLhcoreClassModelDepartament & $depar if ( $form->hasValidData( 'theme_ind' ) ) { - $botConfiguration['theme_ind'] = $form->theme_ind; + $botConfiguration['theme_ind'] = implode(',',$form->theme_ind); } else { $botConfiguration['theme_ind'] = 0; } diff --git a/lhc_web/modules/lhchat/start.php b/lhc_web/modules/lhchat/start.php index 1486567d30..2c3f70d133 100644 --- a/lhc_web/modules/lhchat/start.php +++ b/lhc_web/modules/lhchat/start.php @@ -58,6 +58,50 @@ return $Result; } +$vid = $Params['user_parameters_unordered']['vid'] != '' ? $Params['user_parameters_unordered']['vid'] : null; + +if (empty($vid) && !((isset($_GET['cd']) && $_GET['cd'] == 1) || erLhcoreClassModelChatConfig::fetch('track_online_visitors')->current_value != 1)) { + + // Incorrect mod_rewrite rule as fetch was for an image. + if ((isset($_SERVER['HTTP_SEC_FETCH_DEST']) && $_SERVER['HTTP_SEC_FETCH_DEST'] == 'image') || + (isset($_SERVER['HTTP_USER_AGENT']) && erLhcoreClassModelChatOnlineUser::isBot($_SERVER['HTTP_USER_AGENT'])) + ) { + http_response_code(404); + exit; + } + + if (isset($_COOKIE['lhc_vid']) && $_COOKIE['lhc_vid'] != 'undefined') { + $vid = $_COOKIE['lhc_vid']; + } else { + $vid = substr(sha1(mt_rand() . microtime()),0,20); + } + + setcookie("lhc_vid", $vid, time()+60*60*24*365, '/', '', erLhcoreClassSystem::$httpsMode, true); + $userInstance = erLhcoreClassModelChatOnlineUser::handleRequest(array('tag' => isset($_GET['tag']) ? $_GET['tag'] : false, 'uactiv' => 1, 'wopen' => 0, 'tpl' => & $tpl, 'tz' => (isset($_GET['tz']) ? $_GET['tz'] : null), 'message_seen_timeout' => erLhcoreClassModelChatConfig::fetch('message_seen_timeout')->current_value, 'department' =>( is_array($Params['user_parameters_unordered']['department']) ? $Params['user_parameters_unordered']['department'] : array()), 'identifier' => (isset($_GET['idnt']) ? (string)$_GET['idnt'] : ''), 'pages_count' => true, 'vid' => $vid, 'check_message_operator' => false, 'pro_active_limitation' => erLhcoreClassModelChatConfig::fetch('pro_active_limitation')->current_value, 'pro_active_invite' => false)); +} elseif (!empty($vid)) { + $userInstance = erLhcoreClassModelChatOnlineUser::fetchByVid($vid); +} + +$themeArray = []; + +if (isset($Params['user_parameters_unordered']['theme'])) { + $themeArray = explode(',', $Params['user_parameters_unordered']['theme']); +} + +$setTheme = false; + +if (count($themeArray) > 1 && isset($userInstance) && $userInstance !== false) { + $userAttributes = $userInstance->online_attr_system_array; + if (isset($userAttributes['lhc_theme']) && in_array($userAttributes['lhc_theme'], $themeArray) && isset($userAttributes['lhc_theme_exp']) && $userAttributes['lhc_theme_exp'] > time()) { + $Params['user_parameters_unordered']['theme'] = $userAttributes['lhc_theme']; + } else { + $setTheme = true; + $Params['user_parameters_unordered']['theme'] = $themeArray[array_rand($themeArray)]; + } +} elseif (count($themeArray) > 1) { + $Params['user_parameters_unordered']['theme'] = $themeArray[array_rand($themeArray)]; +} + if (isset($Params['user_parameters_unordered']['theme']) && ($themeId = erLhcoreClassChat::extractTheme($Params['user_parameters_unordered']['theme'])) !== false) { $Params['user_parameters_unordered']['theme'] = $themeId; } @@ -68,20 +112,43 @@ $departmentObject = erLhcoreClassModelDepartament::fetch($dep_id); if (is_object($departmentObject)) { - if (isset($departmentObject->bot_configuration_array['theme_ind']) && $departmentObject->bot_configuration_array['theme_ind'] > 0) { - $Params['user_parameters_unordered']['theme'] = $departmentObject->bot_configuration_array['theme_ind']; + if (isset($departmentObject->bot_configuration_array['theme_ind']) && $departmentObject->bot_configuration_array['theme_ind'] != 0) { + $Params['user_parameters_unordered']['theme'] = explode(',', $departmentObject->bot_configuration_array['theme_ind']); + } + + if (!isset($Params['user_parameters_unordered']['theme']) && isset($departmentObject->bot_configuration_array['theme_default']) && $departmentObject->bot_configuration_array['theme_default'] != 0) { + $Params['user_parameters_unordered']['theme'] = explode(',', $departmentObject->bot_configuration_array['theme_default']); } - if (!is_numeric($Params['user_parameters_unordered']['theme']) && isset($departmentObject->bot_configuration_array['theme_default']) && $departmentObject->bot_configuration_array['theme_default'] > 0) { - $Params['user_parameters_unordered']['theme'] = $departmentObject->bot_configuration_array['theme_default']; + if (isset($Params['user_parameters_unordered']['theme']) && count($Params['user_parameters_unordered']['theme']) > 1 && isset($userInstance) && $userInstance !== false) { + $userAttributes = $userInstance->online_attr_system_array; + if (isset($userAttributes['lhc_theme']) && in_array($userAttributes['lhc_theme'],$Params['user_parameters_unordered']['theme']) && isset($userAttributes['lhc_theme_exp']) && $userAttributes['lhc_theme_exp'] > time()) { + $Params['user_parameters_unordered']['theme'] = $userAttributes['lhc_theme']; + } else { + $setTheme = true; + $Params['user_parameters_unordered']['theme'] =$Params['user_parameters_unordered']['theme'][array_rand($Params['user_parameters_unordered']['theme'])]; + } + } elseif (isset($Params['user_parameters_unordered']['theme'])) { + $Params['user_parameters_unordered']['theme'] = $Params['user_parameters_unordered']['theme'][array_rand($Params['user_parameters_unordered']['theme'])]; } } } if (!is_numeric($Params['user_parameters_unordered']['theme'])) { $defaultTheme = erLhcoreClassModelChatConfig::fetch('default_theme_id')->current_value; - if ($defaultTheme > 0) { - $Params['user_parameters_unordered']['theme'] = (int)$defaultTheme; + if ($defaultTheme != '0' && $defaultTheme != '') { + $themeArray = explode(',', $defaultTheme); + if (count($themeArray) > 1 && isset($userInstance) && $userInstance !== false) { + $userAttributes = $userInstance->online_attr_system_array; + if (isset($userAttributes['lhc_theme']) && in_array($userAttributes['lhc_theme'], $themeArray) && isset($userAttributes['lhc_theme_exp']) && $userAttributes['lhc_theme_exp'] > time()) { + $Params['user_parameters_unordered']['theme'] = $userAttributes['lhc_theme']; + } else { + $setTheme = true; + $Params['user_parameters_unordered']['theme'] = $themeArray[array_rand($themeArray)]; + } + } else { + $Params['user_parameters_unordered']['theme'] = $themeArray[array_rand($themeArray)]; + } } } } @@ -98,29 +165,6 @@ $tpl->set('hash',$Params['user_parameters_unordered']['hash'] != '' ? $Params['user_parameters_unordered']['hash'] : null); $tpl->set('isMobile',$Params['user_parameters_unordered']['mobile'] == 'true'); $tpl->set('theme',$Params['user_parameters_unordered']['theme'] > 0 ? (int)$Params['user_parameters_unordered']['theme'] : null); - -$vid = $Params['user_parameters_unordered']['vid'] != '' ? $Params['user_parameters_unordered']['vid'] : null; - -if (empty($vid) && !((isset($_GET['cd']) && $_GET['cd'] == 1) || erLhcoreClassModelChatConfig::fetch('track_online_visitors')->current_value != 1)) { - - // Incorrect mod_rewrite rule as fetch was for an image. - if ((isset($_SERVER['HTTP_SEC_FETCH_DEST']) && $_SERVER['HTTP_SEC_FETCH_DEST'] == 'image') || - (isset($_SERVER['HTTP_USER_AGENT']) && erLhcoreClassModelChatOnlineUser::isBot($_SERVER['HTTP_USER_AGENT'])) - ) { - http_response_code(404); - exit; - } - - if (isset($_COOKIE['lhc_vid']) && $_COOKIE['lhc_vid'] != 'undefined') { - $vid = $_COOKIE['lhc_vid']; - } else { - $vid = substr(sha1(mt_rand() . microtime()),0,20); - } - - setcookie("lhc_vid", $vid, time()+60*60*24*365, '/', '', erLhcoreClassSystem::$httpsMode, true); - erLhcoreClassModelChatOnlineUser::handleRequest(array('tag' => isset($_GET['tag']) ? $_GET['tag'] : false, 'uactiv' => 1, 'wopen' => 0, 'tpl' => & $tpl, 'tz' => (isset($_GET['tz']) ? $_GET['tz'] : null), 'message_seen_timeout' => erLhcoreClassModelChatConfig::fetch('message_seen_timeout')->current_value, 'department' =>( is_array($Params['user_parameters_unordered']['department']) ? $Params['user_parameters_unordered']['department'] : array()), 'identifier' => (isset($_GET['idnt']) ? (string)$_GET['idnt'] : ''), 'pages_count' => true, 'vid' => $vid, 'check_message_operator' => false, 'pro_active_limitation' => erLhcoreClassModelChatConfig::fetch('pro_active_limitation')->current_value, 'pro_active_invite' => false)); -} - $tpl->set('vid',$vid); $tpl->set('identifier',$Params['user_parameters_unordered']['identifier'] != '' ? $Params['user_parameters_unordered']['identifier'] : null); $tpl->set('inv',$Params['user_parameters_unordered']['inv'] != '' ? $Params['user_parameters_unordered']['inv'] : null); @@ -212,6 +256,15 @@ $themeObject = erLhAbstractModelWidgetTheme::fetch($Params['user_parameters_unordered']['theme']); if ($themeObject instanceof erLhAbstractModelWidgetTheme) { + + if ($setTheme === true && isset($themeObject->bot_configuration_array['theme_expires']) && (int)$themeObject->bot_configuration_array['theme_expires'] > 0 && isset($userInstance) && $userInstance !== false) { + $userAttributes['lhc_theme'] = $Params['user_parameters_unordered']['theme']; + $userAttributes['lhc_theme_exp'] = time() + $themeObject->bot_configuration_array['theme_expires']; + $userInstance->online_attr_system_array = $userAttributes; + $userInstance->online_attr_system = json_encode($userAttributes); + $userInstance->updateThis(['update' => ['online_attr_system']]); + } + $Result['theme'] = $themeObject; $Result['theme_v'] = $themeObject->modified; } else { diff --git a/lhc_web/modules/lhtheme/default.php b/lhc_web/modules/lhtheme/default.php index d17c29711b..2b716d12f7 100644 --- a/lhc_web/modules/lhtheme/default.php +++ b/lhc_web/modules/lhtheme/default.php @@ -13,7 +13,7 @@ $definition = array( 'ThemeID' => new ezcInputFormDefinitionElement( - ezcInputFormDefinitionElement::OPTIONAL, 'int',array('min_range' => 1) + ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1), FILTER_REQUIRE_ARRAY ), 'department_default' => new ezcInputFormDefinitionElement( ezcInputFormDefinitionElement::OPTIONAL, 'boolean' @@ -23,7 +23,7 @@ $form = new ezcInputForm( INPUT_POST, $definition ); if ( $form->hasValidData( 'ThemeID' ) ) { - $themeData->value = $form->ThemeID; + $themeData->value = implode(',',$form->ThemeID); } else { $themeData->value = 0; } @@ -47,6 +47,6 @@ $tpl->set('updated',true); } -$tpl->set('default_theme_id',$themeData->value); +$tpl->set('default_theme_id',explode(',',$themeData->value)); $Result['path'] = array(array('url' => erLhcoreClassDesign::baseurl('system/configuration'),'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('department/edit','System configuration')),array('url' => erLhcoreClassDesign::baseurl('theme/index'),'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('theme/index','Themes')),array('title' => erTranslationClassLhTranslation::getInstance()->getTranslation('theme/index','Default theme'))); $Result['content'] = $tpl->fetch(); \ No newline at end of file diff --git a/lhc_web/modules/lhwidgetrestapi/settings.php b/lhc_web/modules/lhwidgetrestapi/settings.php index 9530dab1c4..ed000c7ef7 100644 --- a/lhc_web/modules/lhwidgetrestapi/settings.php +++ b/lhc_web/modules/lhwidgetrestapi/settings.php @@ -156,7 +156,7 @@ if (count($themeArray) > 1 && isset($userInstance) && $userInstance !== false) { $userAttributes = $userInstance->online_attr_system_array; - if (isset($userAttributes['lhc_theme']) && isset($userAttributes['lhc_theme_exp']) && $userAttributes['lhc_theme_exp'] > time()) { + if (isset($userAttributes['lhc_theme']) && in_array($userAttributes['lhc_theme'],$themeArray) && isset($userAttributes['lhc_theme_exp']) && $userAttributes['lhc_theme_exp'] > time()) { $_GET['theme'] = $userAttributes['lhc_theme']; } else { $setTheme = true; @@ -184,20 +184,43 @@ $departmentObject = erLhcoreClassModelDepartament::fetch($dep_id); if (is_object($departmentObject)) { - if (isset($departmentObject->bot_configuration_array['theme_ind']) && $departmentObject->bot_configuration_array['theme_ind'] > 0) { - $outputResponse['theme'] = $departmentObject->bot_configuration_array['theme_ind']; + if (isset($departmentObject->bot_configuration_array['theme_ind']) && $departmentObject->bot_configuration_array['theme_ind'] != 0) { + $outputResponse['theme'] = explode(',', $departmentObject->bot_configuration_array['theme_ind']); } - if (!isset($outputResponse['theme']) && isset($departmentObject->bot_configuration_array['theme_default']) && $departmentObject->bot_configuration_array['theme_default'] > 0) { - $outputResponse['theme'] = $departmentObject->bot_configuration_array['theme_default']; + if (!isset($outputResponse['theme']) && isset($departmentObject->bot_configuration_array['theme_default']) && $departmentObject->bot_configuration_array['theme_default'] != 0) { + $outputResponse['theme'] = explode(',', $departmentObject->bot_configuration_array['theme_default']); + } + + if (isset($outputResponse['theme']) && count($outputResponse['theme']) > 1 && isset($userInstance) && $userInstance !== false) { + $userAttributes = $userInstance->online_attr_system_array; + if (isset($userAttributes['lhc_theme']) && in_array($userAttributes['lhc_theme'],$outputResponse['theme']) && isset($userAttributes['lhc_theme_exp']) && $userAttributes['lhc_theme_exp'] > time()) { + $outputResponse['theme'] = $userAttributes['lhc_theme']; + } else { + $setTheme = true; + $outputResponse['theme'] = $outputResponse['theme'][array_rand($outputResponse['theme'])]; + } + } elseif (isset($outputResponse['theme'])) { + $outputResponse['theme'] = $outputResponse['theme'][array_rand($outputResponse['theme'])]; } } } if (!isset($outputResponse['theme'])) { $defaultTheme = erLhcoreClassModelChatConfig::fetch('default_theme_id')->current_value; - if ($defaultTheme > 0) { - $outputResponse['theme'] = (int)$defaultTheme; + if ($defaultTheme != '0' && $defaultTheme != '') { + $themeArray = explode(',', $defaultTheme); + if (count($themeArray) > 1 && isset($userInstance) && $userInstance !== false) { + $userAttributes = $userInstance->online_attr_system_array; + if (isset($userAttributes['lhc_theme']) && in_array($userAttributes['lhc_theme'],$themeArray) && isset($userAttributes['lhc_theme_exp']) && $userAttributes['lhc_theme_exp'] > time()) { + $outputResponse['theme'] = $userAttributes['lhc_theme']; + } else { + $setTheme = true; + $outputResponse['theme'] = $themeArray[array_rand($themeArray)]; + } + } else { + $outputResponse['theme'] = $themeArray[array_rand($themeArray)]; + } } } }