Skip to content

Commit

Permalink
Multi theme support
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Dec 20, 2022
1 parent 105c068 commit 0a0bccd
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('department/edit','Individual theme');?></label>
<?php echo erLhcoreClassRenderHelper::renderCombobox( array (
'input_name' => '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'
)); ?>
</div>

<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('department/edit','Default theme applied per department');?></label> - <b><?php (isset($departament->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';?></b>
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('department/edit','Default theme applied per department');?></label>
<?php foreach (explode(',',$departament->bot_configuration_array['theme_default']) as $themeDefault) : if ((int)$themeDefault > 0) : ?>
<span class="badge badge-success ml-1"> <?php print htmlspecialchars(erLhAbstractModelWidgetTheme::fetch((int)$themeDefault)) ?></span>
<?php endif; endforeach; ?>
</b>
<p><small><i><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('department/edit','This theme is set from');?> <a href="<?php echo erLhcoreClassDesign::baseurl('theme/default')?>"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('department/edit','Default theme');?></a> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('department/edit','section and checking As default department theme.');?></i></small></p>
</div>

<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('department/edit','Theme global');?></label> - <b><?php erLhcoreClassModelChatConfig::fetch('default_theme_id')->current_value > 0 ? print htmlspecialchars(erLhAbstractModelWidgetTheme::fetch(erLhcoreClassModelChatConfig::fetch('default_theme_id')->current_value)) : print 'n/a';?></b>
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('department/edit','Theme global');?></label> -

<?php foreach (explode(',',erLhcoreClassModelChatConfig::fetch('default_theme_id')->current_value) as $themeDefault) : if ((int)$themeDefault > 0) : ?>
<span class="badge badge-success ml-1"> <?php print htmlspecialchars(erLhAbstractModelWidgetTheme::fetch((int)$themeDefault)) ?></span>
<?php endif; endforeach; ?>

<p><small><i><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('department/edit','If you are using only');?> <a href="<?php echo erLhcoreClassDesign::baseurl('theme/default')?>">Default theme</a> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('department/edit','option and you have more than one server you might get inconsistent theme pickup. Apply');?> <a href="<?php echo erLhcoreClassDesign::baseurl('theme/default')?>"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('department/edit','Default theme');?></a> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('department/edit','to department as default or choose individual theme.');?></i></small></p>
</div>
6 changes: 4 additions & 2 deletions lhc_web/design/defaulttheme/tpl/lhstatistic/userstats.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@
<?php endif; ?>
</td>
<td>
<?php if ($operator['exclude_autoasign'] == 1) : ?>
<span class="text-danger"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Yes');?></span>
<?php if ($operator['exclude_autoasign'] == 1 || $operator['exc_indv_autoasign'] == 1) : ?>
<span class="text-danger">
<span class="material-icons"><?php if ($operator['exclude_autoasign'] == 1) : ?>home<?php else : ?>account_balance<?php endif;?></span><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Yes');?>
</span>
<?php else : ?>
<span class="text-success"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','No');?></span>
<?php endif; ?>
Expand Down
6 changes: 3 additions & 3 deletions lhc_web/design/defaulttheme/tpl/lhtheme/default.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<?php include(erLhcoreClassDesign::designtpl('lhkernel/csfr_token.tpl.php'));?>

<div class="form-group" ng-non-bindable>
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/htmlcode','Theme')?></label>
<select name="ThemeID" class="form-control form-control-sm">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/htmlcode','Theme, you can choose multiple to show random one.')?></label>
<select name="ThemeID[]" class="form-control form-control-sm" multiple size="5">
<option value="0">--<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/htmlcode','Default');?>--</option>
<?php foreach (erLhAbstractModelWidgetTheme::getList(array('limit' => false, 'sort' => '`name` ASC')) as $theme) : ?>
<option value="<?php echo $theme->id?>" <?php $default_theme_id == $theme->id ? print 'selected="selected"' : '';?>><?php echo htmlspecialchars($theme->name)?></option>
<option value="<?php echo $theme->id?>" <?php in_array($theme->id,$default_theme_id) ? print 'selected="selected"' : '';?>><?php echo htmlspecialchars($theme->name)?></option>
<?php endforeach; ?>
</select>
</div>
Expand Down
4 changes: 2 additions & 2 deletions lhc_web/lib/core/lhdepartament/lhdepartament.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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;
}
Expand Down
111 changes: 82 additions & 29 deletions lhc_web/modules/lhchat/start.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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)];
}
}
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions lhc_web/modules/lhtheme/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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;
}
Expand All @@ -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();
Loading

0 comments on commit 0a0bccd

Please sign in to comment.