mirror of
https://github.com/Mibew/mibew.git
synced 2025-02-01 05:44:41 +03:00
Encapsulate default style storage in *Style classes
This commit is contained in:
parent
45a70affce
commit
c9ab51dbb2
@ -44,7 +44,10 @@ class ChatStyle extends Style implements StyleInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns name of the style which is currently used in the system
|
* Returns name of the style which shoud be used for the current request.
|
||||||
|
*
|
||||||
|
* Result of the method can depends on user role, requested page or any
|
||||||
|
* other criteria.
|
||||||
*
|
*
|
||||||
* @return string Name of a style
|
* @return string Name of a style
|
||||||
*/
|
*/
|
||||||
@ -52,8 +55,8 @@ class ChatStyle extends Style implements StyleInterface {
|
|||||||
// Ceck if request contains chat style
|
// Ceck if request contains chat style
|
||||||
$style_name = verifyparam("style", "/^\w+$/", "");
|
$style_name = verifyparam("style", "/^\w+$/", "");
|
||||||
if (!$style_name) {
|
if (!$style_name) {
|
||||||
// Load value from system settings
|
// Use the default style
|
||||||
$style_name = Settings::get('chat_style');
|
$style_name = self::defaultStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all style list and make sure that in has at least one style.
|
// Get all style list and make sure that in has at least one style.
|
||||||
@ -75,11 +78,21 @@ class ChatStyle extends Style implements StyleInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets style which is currently used in the system
|
* Returns name of the style which is used in the system by default.
|
||||||
|
*
|
||||||
|
* @return string Name of a style
|
||||||
|
*/
|
||||||
|
public static function defaultStyle() {
|
||||||
|
// Load value from system settings
|
||||||
|
return Settings::get('chat_style');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets style which is used in the system by default
|
||||||
*
|
*
|
||||||
* @param string $style_name Name of a style
|
* @param string $style_name Name of a style
|
||||||
*/
|
*/
|
||||||
public static function setCurrentStyle($style_name) {
|
public static function setDefaultStyle($style_name) {
|
||||||
Settings::set('chat_style', $style_name);
|
Settings::set('chat_style', $style_name);
|
||||||
Settings::update();
|
Settings::update();
|
||||||
}
|
}
|
||||||
|
@ -49,21 +49,34 @@ class InvitationStyle extends Style implements StyleInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns name of the style which is currently used in the system
|
* Returns name of the style which shoud be used for the current request.
|
||||||
|
*
|
||||||
|
* Result of the method can depends on user role, requested page or any
|
||||||
|
* other criteria.
|
||||||
*
|
*
|
||||||
* @return string Name of a style
|
* @return string Name of a style
|
||||||
*/
|
*/
|
||||||
public static function currentStyle() {
|
public static function currentStyle() {
|
||||||
|
// Just use the default style
|
||||||
|
return self::defaultStyle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns name of the style which is used in the system by default.
|
||||||
|
*
|
||||||
|
* @return string Name of a style
|
||||||
|
*/
|
||||||
|
public static function defaultStyle() {
|
||||||
// Load value from system settings
|
// Load value from system settings
|
||||||
return Settings::get('invitation_style');
|
return Settings::get('invitation_style');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets style which is currently used in the system
|
* Sets style which is used in the system by default
|
||||||
*
|
*
|
||||||
* @param string $style_name Name of a style
|
* @param string $style_name Name of a style
|
||||||
*/
|
*/
|
||||||
public static function setCurrentStyle($style_name) {
|
public static function setDefaultStyle($style_name) {
|
||||||
Settings::set('invitation_style', $style_name);
|
Settings::set('invitation_style', $style_name);
|
||||||
Settings::update();
|
Settings::update();
|
||||||
}
|
}
|
||||||
|
@ -55,21 +55,34 @@ class PageStyle extends Style implements StyleInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns name of the style which is currently used in the system
|
* Returns name of the style which shoud be used for the current request.
|
||||||
|
*
|
||||||
|
* Result of the method can depends on user role, requested page or any
|
||||||
|
* other criteria.
|
||||||
*
|
*
|
||||||
* @return string Name of a style
|
* @return string Name of a style
|
||||||
*/
|
*/
|
||||||
public static function currentStyle() {
|
public static function currentStyle() {
|
||||||
|
// Just use the default style
|
||||||
|
return self::defaultStyle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns name of the style which is used in the system by default.
|
||||||
|
*
|
||||||
|
* @return string Name of a style
|
||||||
|
*/
|
||||||
|
public static function defaultStyle() {
|
||||||
// Load value from system settings
|
// Load value from system settings
|
||||||
return Settings::get('page_style');
|
return Settings::get('page_style');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets style which is currently used in the system
|
* Sets style which is used in the system by default
|
||||||
*
|
*
|
||||||
* @param string $style_name Name of a style
|
* @param string $style_name Name of a style
|
||||||
*/
|
*/
|
||||||
public static function setCurrentStyle($style_name) {
|
public static function setDefaultStyle($style_name) {
|
||||||
Settings::set('page_style', $style_name);
|
Settings::set('page_style', $style_name);
|
||||||
Settings::update();
|
Settings::update();
|
||||||
}
|
}
|
||||||
|
@ -20,18 +20,28 @@
|
|||||||
*/
|
*/
|
||||||
interface StyleInterface {
|
interface StyleInterface {
|
||||||
/**
|
/**
|
||||||
* Returns name of the style which is currently used in the system
|
* Returns name of the style which shoud be used for the current request.
|
||||||
|
*
|
||||||
|
* Result of the method can depends on user role, requested page or any
|
||||||
|
* other criteria.
|
||||||
*
|
*
|
||||||
* @return string Name of a style
|
* @return string Name of a style
|
||||||
*/
|
*/
|
||||||
public static function currentStyle();
|
public static function currentStyle();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets style which is currently used in the system
|
* Returns name of the style which is used in the system by default.
|
||||||
|
*
|
||||||
|
* @return string Name of a style
|
||||||
|
*/
|
||||||
|
public static function defaultStyle();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets style which is used in the system by default
|
||||||
*
|
*
|
||||||
* @param string $style_name Name of a style
|
* @param string $style_name Name of a style
|
||||||
*/
|
*/
|
||||||
public static function setCurrentStyle($style_name);
|
public static function setDefaultStyle($style_name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array which contains names of available styles.
|
* Returns an array which contains names of available styles.
|
||||||
|
@ -32,17 +32,13 @@ csrfchecktoken();
|
|||||||
$page = array('agentId' => '');
|
$page = array('agentId' => '');
|
||||||
$errors = array();
|
$errors = array();
|
||||||
|
|
||||||
$stylelist = ChatStyle::availableStyles();
|
// Load system configs
|
||||||
$page_style_list = PageStyle::availableStyles();
|
|
||||||
|
|
||||||
$options = array(
|
$options = array(
|
||||||
'email',
|
'email',
|
||||||
'title',
|
'title',
|
||||||
'logo',
|
'logo',
|
||||||
'hosturl',
|
'hosturl',
|
||||||
'usernamepattern',
|
'usernamepattern',
|
||||||
'page_style',
|
|
||||||
'chat_style',
|
|
||||||
'chattitle',
|
'chattitle',
|
||||||
'geolink',
|
'geolink',
|
||||||
'geolinkparams',
|
'geolinkparams',
|
||||||
@ -50,16 +46,25 @@ $options = array(
|
|||||||
'cron_key'
|
'cron_key'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Settings::get('enabletracking')) {
|
|
||||||
$options[] = 'invitation_style';
|
|
||||||
$invitationstylelist = InvitationStyle::availableStyles();
|
|
||||||
}
|
|
||||||
|
|
||||||
$params = array();
|
$params = array();
|
||||||
foreach ($options as $opt) {
|
foreach ($options as $opt) {
|
||||||
$params[$opt] = Settings::get($opt);
|
$params[$opt] = Settings::get($opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load styles configs
|
||||||
|
$styles_params = array(
|
||||||
|
'chat_style' => ChatStyle::defaultStyle(),
|
||||||
|
'page_style' => PageStyle::defaultStyle(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$chat_style_list = ChatStyle::availableStyles();
|
||||||
|
$page_style_list = PageStyle::availableStyles();
|
||||||
|
|
||||||
|
if (Settings::get('enabletracking')) {
|
||||||
|
$styles_params['invitation_style'] = InvitationStyle::defaultStyle();
|
||||||
|
$invitation_style_list = InvitationStyle::availableStyles();
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($_POST['email']) && isset($_POST['title']) && isset($_POST['logo'])) {
|
if (isset($_POST['email']) && isset($_POST['title']) && isset($_POST['logo'])) {
|
||||||
$params['email'] = getparam('email');
|
$params['email'] = getparam('email');
|
||||||
$params['title'] = getparam('title');
|
$params['title'] = getparam('title');
|
||||||
@ -72,20 +77,20 @@ if (isset($_POST['email']) && isset($_POST['title']) && isset($_POST['logo'])) {
|
|||||||
$params['sendmessagekey'] = verifyparam('sendmessagekey', "/^c?enter$/");
|
$params['sendmessagekey'] = verifyparam('sendmessagekey', "/^c?enter$/");
|
||||||
$params['cron_key'] = getparam('cronkey');
|
$params['cron_key'] = getparam('cronkey');
|
||||||
|
|
||||||
$params['chat_style'] = verifyparam("chat_style", "/^\w+$/", $params['chat_style']);
|
$styles_params['chat_style'] = verifyparam("chat_style", "/^\w+$/", $styles_params['chat_style']);
|
||||||
if (!in_array($params['chat_style'], $stylelist)) {
|
if (!in_array($styles_params['chat_style'], $chat_style_list)) {
|
||||||
$params['chat_style'] = $stylelist[0];
|
$styles_params['chat_style'] = $chat_style_list[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$params['page_style'] = verifyparam("page_style", "/^\w+$/", $params['page_style']);
|
$styles_params['page_style'] = verifyparam("page_style", "/^\w+$/", $styles_params['page_style']);
|
||||||
if (!in_array($params['page_style'], $page_style_list)) {
|
if (!in_array($styles_params['page_style'], $page_style_list)) {
|
||||||
$params['page_style'] = $page_style_list[0];
|
$styles_params['page_style'] = $page_style_list[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings::get('enabletracking')) {
|
if (Settings::get('enabletracking')) {
|
||||||
$params['invitation_style'] = verifyparam("invitation_style", "/^\w+$/", $params['invitation_style']);
|
$styles_params['invitation_style'] = verifyparam("invitation_style", "/^\w+$/", $styles_params['invitation_style']);
|
||||||
if (!in_array($params['invitation_style'], $invitationstylelist)) {
|
if (!in_array($styles_params['invitation_style'], $invitation_style_list)) {
|
||||||
$params['invitation_style'] = $invitationstylelist[0];
|
$styles_params['invitation_style'] = $invitation_style_list[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,10 +111,20 @@ if (isset($_POST['email']) && isset($_POST['title']) && isset($_POST['logo'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count($errors) == 0) {
|
if (count($errors) == 0) {
|
||||||
|
// Update system settings
|
||||||
foreach ($options as $opt) {
|
foreach ($options as $opt) {
|
||||||
Settings::set($opt,$params[$opt]);
|
Settings::set($opt,$params[$opt]);
|
||||||
}
|
}
|
||||||
Settings::update();
|
Settings::update();
|
||||||
|
|
||||||
|
// Update styles params
|
||||||
|
ChatStyle::setDefaultStyle($styles_params['chat_style']);
|
||||||
|
PageStyle::setDefaultStyle($styles_params['page_style']);
|
||||||
|
if (Settings::get('enabletracking')) {
|
||||||
|
InvitationStyle::setDefaultStyle($styles_params['invitation_style']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redirect the user
|
||||||
header("Location: $mibewroot/operator/settings.php?stored");
|
header("Location: $mibewroot/operator/settings.php?stored");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -122,12 +137,12 @@ $page['formhosturl'] = topage($params['hosturl']);
|
|||||||
$page['formgeolink'] = topage($params['geolink']);
|
$page['formgeolink'] = topage($params['geolink']);
|
||||||
$page['formgeolinkparams'] = topage($params['geolinkparams']);
|
$page['formgeolinkparams'] = topage($params['geolinkparams']);
|
||||||
$page['formusernamepattern'] = topage($params['usernamepattern']);
|
$page['formusernamepattern'] = topage($params['usernamepattern']);
|
||||||
$page['formpagestyle'] = $params['page_style'];
|
$page['formpagestyle'] = $styles_params['page_style'];
|
||||||
$page['availablePageStyles'] = $page_style_list;
|
$page['availablePageStyles'] = $page_style_list;
|
||||||
$page['formchatstyle'] = $params['chat_style'];
|
$page['formchatstyle'] = $styles_params['chat_style'];
|
||||||
$page['formchattitle'] = topage($params['chattitle']);
|
$page['formchattitle'] = topage($params['chattitle']);
|
||||||
$page['formsendmessagekey'] = $params['sendmessagekey'];
|
$page['formsendmessagekey'] = $params['sendmessagekey'];
|
||||||
$page['availableChatStyles'] = $stylelist;
|
$page['availableChatStyles'] = $chat_style_list;
|
||||||
$page['stored'] = isset($_GET['stored']);
|
$page['stored'] = isset($_GET['stored']);
|
||||||
$page['enabletracking'] = Settings::get('enabletracking');
|
$page['enabletracking'] = Settings::get('enabletracking');
|
||||||
$page['formcronkey'] = $params['cron_key'];
|
$page['formcronkey'] = $params['cron_key'];
|
||||||
@ -135,8 +150,8 @@ $page['formcronkey'] = $params['cron_key'];
|
|||||||
$page['cron_path'] = cron_get_uri($params['cron_key']);
|
$page['cron_path'] = cron_get_uri($params['cron_key']);
|
||||||
|
|
||||||
if (Settings::get('enabletracking')) {
|
if (Settings::get('enabletracking')) {
|
||||||
$page['forminvitationstyle'] = $params['invitation_style'];
|
$page['forminvitationstyle'] = $styles_params['invitation_style'];
|
||||||
$page['availableInvitationStyles'] = $invitationstylelist;
|
$page['availableInvitationStyles'] = $invitation_style_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare_menu($operator);
|
prepare_menu($operator);
|
||||||
|
Loading…
Reference in New Issue
Block a user