mirror of
https://github.com/Mibew/mibew.git
synced 2025-02-08 00:34:42 +03:00
Replace "operator/getcode.php" with a controller
This commit is contained in:
parent
090ebdb332
commit
f5cb3ec179
175
src/mibew/libs/classes/Mibew/Controller/ButtonCodeController.php
Normal file
175
src/mibew/libs/classes/Mibew/Controller/ButtonCodeController.php
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright 2005-2014 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mibew\Controller;
|
||||||
|
|
||||||
|
use Mibew\Http\Exception\BadRequestException;
|
||||||
|
use Mibew\Settings;
|
||||||
|
use Mibew\Style\ChatStyle;
|
||||||
|
use Mibew\Style\InvitationStyle;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents actions that are related with button code generation.
|
||||||
|
*/
|
||||||
|
class ButtonCodeController extends AbstractController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Generates a page with Mibew button code form.
|
||||||
|
*
|
||||||
|
* @param Request $request Incoming request
|
||||||
|
* @return Response Rendered content of the page.
|
||||||
|
*/
|
||||||
|
public function generateAction(Request $request)
|
||||||
|
{
|
||||||
|
$operator = $request->attributes->get('_operator');
|
||||||
|
|
||||||
|
$page = array(
|
||||||
|
'errors' => array(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$image_locales_map = get_image_locales_map(MIBEW_FS_ROOT . '/locales');
|
||||||
|
$image = $request->query->get('i', 'mibew');
|
||||||
|
if (!isset($image_locales_map[$image])) {
|
||||||
|
$page['errors'][] = 'Unknown image: ' . $image;
|
||||||
|
$avail = array_keys($image_locales_map);
|
||||||
|
$image = $avail[0];
|
||||||
|
}
|
||||||
|
$image_locales = $image_locales_map[$image];
|
||||||
|
|
||||||
|
$style_list = ChatStyle::getAvailableStyles();
|
||||||
|
$style_list[''] = getlocal('page.preview.style_default');
|
||||||
|
$style = $request->query->get('style', '');
|
||||||
|
if ($style && !in_array($style, $style_list)) {
|
||||||
|
$style = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$invitation_style_list = InvitationStyle::getAvailableStyles();
|
||||||
|
$invitation_style_list[''] = getlocal('page.preview.style_default');
|
||||||
|
$invitation_style = $request->query->get('invitationstyle', '');
|
||||||
|
if ($invitation_style && !in_array($invitation_style, $invitation_style_list)) {
|
||||||
|
$invitation_style = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$locales_list = get_available_locales();
|
||||||
|
|
||||||
|
$group_id = $request->query->getInt('group');
|
||||||
|
if ($group_id && !group_by_id($group_id)) {
|
||||||
|
$page['errors'][] = getlocal("page.group.no_such");
|
||||||
|
$group_id = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$show_host = $request->query->get('hostname') == 'on';
|
||||||
|
$force_secure = $request->query->get('secure') == 'on';
|
||||||
|
$mod_security = $request->query->get('modsecurity') == 'on';
|
||||||
|
|
||||||
|
$code_type = $request->query->get('codetype', 'button');
|
||||||
|
if (!in_array($code_type, array('button', 'operator_code', 'text_link'))) {
|
||||||
|
throw new BadRequestException('Wrong value of "codetype" param.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$lang = $request->query->get('lang', '');
|
||||||
|
if (!preg_match("/^[\w-]{2,5}$/", $lang)) {
|
||||||
|
$lang = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$operator_code = ($code_type == 'operator_code');
|
||||||
|
$generate_button = ($code_type == 'button');
|
||||||
|
|
||||||
|
if ($generate_button) {
|
||||||
|
$disable_invitation = false;
|
||||||
|
|
||||||
|
if (!$lang || !in_array($lang, $image_locales)) {
|
||||||
|
$lang = in_array(CURRENT_LOCALE, $image_locales)
|
||||||
|
? CURRENT_LOCALE
|
||||||
|
: $image_locales[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
$file = MIBEW_FS_ROOT . '/locales/${lang}/button/${image}_on.gif';
|
||||||
|
$size = get_gifimage_size($file);
|
||||||
|
|
||||||
|
$image_link_args = array(
|
||||||
|
'i' => $image,
|
||||||
|
'lang' => $lang,
|
||||||
|
);
|
||||||
|
if ($group_id) {
|
||||||
|
$image_link_args['group'] = $group_id;
|
||||||
|
}
|
||||||
|
$host = ($force_secure ? 'https://' : 'http://') . $request->getHost();
|
||||||
|
$image_href = ($show_host ? $host : '')
|
||||||
|
. $this->generateUrl('button', $image_link_args, UrlGeneratorInterface::ABSOLUTE_PATH);
|
||||||
|
|
||||||
|
$message = get_image(htmlspecialchars($image_href), $size[0], $size[1]);
|
||||||
|
} else {
|
||||||
|
$disable_invitation = true;
|
||||||
|
|
||||||
|
if (!$lang || !in_array($lang, $locales_list)) {
|
||||||
|
$lang = in_array(CURRENT_LOCALE, $locales_list) ? CURRENT_LOCALE : $locales_list[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = getlocal('page.gen_button.text_link_text');
|
||||||
|
}
|
||||||
|
|
||||||
|
$page['buttonCode'] = generate_button(
|
||||||
|
'',
|
||||||
|
$lang,
|
||||||
|
$style,
|
||||||
|
$invitation_style,
|
||||||
|
$group_id,
|
||||||
|
$message,
|
||||||
|
$show_host,
|
||||||
|
$force_secure,
|
||||||
|
$mod_security,
|
||||||
|
$operator_code,
|
||||||
|
$disable_invitation
|
||||||
|
);
|
||||||
|
$page['availableImages'] = array_keys($image_locales_map);
|
||||||
|
$page['availableLocales'] = $generate_button ? $image_locales : $locales_list;
|
||||||
|
$page['availableChatStyles'] = $style_list;
|
||||||
|
$page['availableInvitationStyles'] = $invitation_style_list;
|
||||||
|
$page['groups'] = get_groups_list();
|
||||||
|
|
||||||
|
$page['availableCodeTypes'] = array(
|
||||||
|
'button' => getlocal('page.gen_button.button'),
|
||||||
|
'operator_code' => getlocal('page.gen_button.operator_code'),
|
||||||
|
'text_link' => getlocal('page.gen_button.text_link')
|
||||||
|
);
|
||||||
|
|
||||||
|
$page['formgroup'] = $group_id;
|
||||||
|
$page['formstyle'] = $style;
|
||||||
|
$page['forminvitationstyle'] = $invitation_style;
|
||||||
|
$page['formimage'] = $image;
|
||||||
|
$page['formlang'] = $lang;
|
||||||
|
$page['formhostname'] = $show_host;
|
||||||
|
$page['formsecure'] = $force_secure;
|
||||||
|
$page['formmodsecurity'] = $mod_security;
|
||||||
|
$page['formcodetype'] = $code_type;
|
||||||
|
|
||||||
|
$page['enabletracking'] = Settings::get('enabletracking');
|
||||||
|
$page['operator_code'] = $operator_code;
|
||||||
|
$page['generateButton'] = $generate_button;
|
||||||
|
|
||||||
|
$page['title'] = getlocal("page.gen_button.title");
|
||||||
|
$page['menuid'] = "getcode";
|
||||||
|
|
||||||
|
$page = array_merge($page, prepare_menu($operator));
|
||||||
|
|
||||||
|
return $this->render('button_code', $page);
|
||||||
|
}
|
||||||
|
}
|
@ -60,6 +60,14 @@ bans:
|
|||||||
_controller: Mibew\Controller\BanController::indexAction
|
_controller: Mibew\Controller\BanController::indexAction
|
||||||
_access_check: Mibew\AccessControl\Check\LoggedInCheck
|
_access_check: Mibew\AccessControl\Check\LoggedInCheck
|
||||||
|
|
||||||
|
## Button code
|
||||||
|
button_code:
|
||||||
|
path: /operator/button-code
|
||||||
|
defaults:
|
||||||
|
_controller: Mibew\Controller\ButtonCodeController::generateAction
|
||||||
|
_access_check: Mibew\AccessControl\Check\PermissionsCheck
|
||||||
|
_access_permissions: [CAN_ADMINISTRATE]
|
||||||
|
|
||||||
## Canned messages
|
## Canned messages
|
||||||
canned_message_add:
|
canned_message_add:
|
||||||
path: /operator/canned-message/add
|
path: /operator/canned-message/add
|
||||||
|
@ -1,140 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* Copyright 2005-2014 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Import namespaces and classes of the core
|
|
||||||
use Mibew\Settings;
|
|
||||||
use Mibew\Style\ChatStyle;
|
|
||||||
use Mibew\Style\InvitationStyle;
|
|
||||||
use Mibew\Style\PageStyle;
|
|
||||||
|
|
||||||
// Initialize libraries
|
|
||||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
|
||||||
|
|
||||||
$operator = check_login();
|
|
||||||
force_password($operator);
|
|
||||||
|
|
||||||
$page = array(
|
|
||||||
'errors' => array(),
|
|
||||||
);
|
|
||||||
|
|
||||||
$image_locales_map = get_image_locales_map(MIBEW_FS_ROOT . '/locales');
|
|
||||||
$image = verify_param(isset($_GET['image']) ? "image" : "i", "/^\w+$/", "mibew");
|
|
||||||
if (!isset($image_locales_map[$image])) {
|
|
||||||
$page['errors'][] = "Unknown image: $image";
|
|
||||||
$avail = array_keys($image_locales_map);
|
|
||||||
$image = $avail[0];
|
|
||||||
}
|
|
||||||
$image_locales = $image_locales_map[$image];
|
|
||||||
|
|
||||||
$style_list = ChatStyle::getAvailableStyles();
|
|
||||||
$style_list[""] = getlocal("page.preview.style_default");
|
|
||||||
$style = verify_param("style", "/^\w*$/", "");
|
|
||||||
if ($style && !in_array($style, $style_list)) {
|
|
||||||
$style = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
$invitation_style_list = InvitationStyle::getAvailableStyles();
|
|
||||||
$invitation_style_list[""] = getlocal("page.preview.style_default");
|
|
||||||
$invitation_style = verify_param("invitationstyle", "/^\w*$/", "");
|
|
||||||
if ($invitation_style && !in_array($invitation_style, $invitation_style_list)) {
|
|
||||||
$invitation_style = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
$locales_list = get_available_locales();
|
|
||||||
|
|
||||||
$group_id = verifyparam_groupid("group", $page['errors']);
|
|
||||||
$show_host = verify_param("hostname", "/^on$/", "") == "on";
|
|
||||||
$force_secure = verify_param("secure", "/^on$/", "") == "on";
|
|
||||||
$mod_security = verify_param("modsecurity", "/^on$/", "") == "on";
|
|
||||||
|
|
||||||
$code_type = verify_param("codetype", "/^(button|operator_code|text_link)$/", "button");
|
|
||||||
$operator_code = ($code_type == "operator_code");
|
|
||||||
$generate_button = ($code_type == "button");
|
|
||||||
|
|
||||||
if ($generate_button) {
|
|
||||||
$disable_invitation = false;
|
|
||||||
|
|
||||||
$lang = verify_param("lang", "/^[\w-]{2,5}$/", "");
|
|
||||||
if (!$lang || !in_array($lang, $image_locales)) {
|
|
||||||
$lang = in_array(CURRENT_LOCALE, $image_locales) ? CURRENT_LOCALE : $image_locales[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$file = MIBEW_FS_ROOT . '/locales/${lang}/button/${image}_on.gif';
|
|
||||||
$size = get_gifimage_size($file);
|
|
||||||
|
|
||||||
$image_href = get_app_location($show_host, $force_secure) . "/b?i=$image&lang=$lang";
|
|
||||||
if ($group_id) {
|
|
||||||
$image_href .= "&group=$group_id";
|
|
||||||
}
|
|
||||||
$message = get_image($image_href, $size[0], $size[1]);
|
|
||||||
} else {
|
|
||||||
$disable_invitation = true;
|
|
||||||
|
|
||||||
$lang = verify_param("lang", "/^[\w-]{2,5}$/", "");
|
|
||||||
if (!$lang || !in_array($lang, $locales_list)) {
|
|
||||||
$lang = in_array(CURRENT_LOCALE, $locales_list) ? CURRENT_LOCALE : $locales_list[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$message = getlocal('page.gen_button.text_link_text');
|
|
||||||
}
|
|
||||||
|
|
||||||
$page['buttonCode'] = generate_button(
|
|
||||||
"",
|
|
||||||
$lang,
|
|
||||||
$style,
|
|
||||||
$invitation_style,
|
|
||||||
$group_id,
|
|
||||||
$message,
|
|
||||||
$show_host,
|
|
||||||
$force_secure,
|
|
||||||
$mod_security,
|
|
||||||
$operator_code,
|
|
||||||
$disable_invitation
|
|
||||||
);
|
|
||||||
$page['availableImages'] = array_keys($image_locales_map);
|
|
||||||
$page['availableLocales'] = $generate_button ? $image_locales : $locales_list;
|
|
||||||
$page['availableChatStyles'] = $style_list;
|
|
||||||
$page['availableInvitationStyles'] = $invitation_style_list;
|
|
||||||
$page['groups'] = get_groups_list();
|
|
||||||
|
|
||||||
$page['availableCodeTypes'] = array(
|
|
||||||
'button' => getlocal('page.gen_button.button'),
|
|
||||||
'operator_code' => getlocal('page.gen_button.operator_code'),
|
|
||||||
'text_link' => getlocal('page.gen_button.text_link')
|
|
||||||
);
|
|
||||||
|
|
||||||
$page['formgroup'] = $group_id;
|
|
||||||
$page['formstyle'] = $style;
|
|
||||||
$page['forminvitationstyle'] = $invitation_style;
|
|
||||||
$page['formimage'] = $image;
|
|
||||||
$page['formlang'] = $lang;
|
|
||||||
$page['formhostname'] = $show_host;
|
|
||||||
$page['formsecure'] = $force_secure;
|
|
||||||
$page['formmodsecurity'] = $mod_security;
|
|
||||||
$page['formcodetype'] = $code_type;
|
|
||||||
|
|
||||||
$page['enabletracking'] = Settings::get('enabletracking');
|
|
||||||
$page['operator_code'] = $operator_code;
|
|
||||||
$page['generateButton'] = $generate_button;
|
|
||||||
|
|
||||||
$page['title'] = getlocal("page.gen_button.title");
|
|
||||||
$page['menuid'] = "getcode";
|
|
||||||
|
|
||||||
$page = array_merge($page, prepare_menu($operator));
|
|
||||||
|
|
||||||
$page_style = new PageStyle(PageStyle::getCurrentStyle());
|
|
||||||
$page_style->render('get_code', $page);
|
|
@ -28,7 +28,7 @@
|
|||||||
<ul class="submenu">
|
<ul class="submenu">
|
||||||
<li{{#ifEqual menuid "canned"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/canned-message">{{l10n "menu.canned"}}</a></li>
|
<li{{#ifEqual menuid "canned"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/canned-message">{{l10n "menu.canned"}}</a></li>
|
||||||
{{#if showadmin}}
|
{{#if showadmin}}
|
||||||
<li{{#ifEqual menuid "getcode"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/getcode.php">{{l10n "leftMenu.client_gen_button"}}</a></li>
|
<li{{#ifEqual menuid "getcode"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/button-code">{{l10n "leftMenu.client_gen_button"}}</a></li>
|
||||||
<li{{#ifEqual menuid "operators"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/operator">{{l10n "leftMenu.client_agents"}}</a></li>
|
<li{{#ifEqual menuid "operators"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/operator">{{l10n "leftMenu.client_agents"}}</a></li>
|
||||||
<li{{#ifEqual menuid "groups"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/group">{{l10n "menu.groups"}}</a></li>
|
<li{{#ifEqual menuid "groups"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/group">{{l10n "menu.groups"}}</a></li>
|
||||||
<li{{#ifEqual menuid "settings"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/settings">{{l10n "leftMenu.client_settings"}}</a></li>
|
<li{{#ifEqual menuid "settings"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/settings">{{l10n "leftMenu.client_settings"}}</a></li>
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
{{> _errors}}
|
{{> _errors}}
|
||||||
|
|
||||||
<form name="buttonCodeForm" method="get" action="{{mibewRoot}}/operator/getcode.php">
|
<form name="buttonCodeForm" method="get" action="{{mibewRoot}}/operator/button-code">
|
||||||
<div class="mform">
|
<div class="mform">
|
||||||
<div class="formtop">
|
<div class="formtop">
|
||||||
<div class="formtopi"></div>
|
<div class="formtopi"></div>
|
@ -84,7 +84,7 @@
|
|||||||
<div class="dashitem">
|
<div class="dashitem">
|
||||||
<div class="dashitem-content">
|
<div class="dashitem-content">
|
||||||
<img src="{{stylePath}}/images/dash/getcode.gif" alt=""/>
|
<img src="{{stylePath}}/images/dash/getcode.gif" alt=""/>
|
||||||
<a href="{{mibewRoot}}/operator/getcode.php">
|
<a href="{{mibewRoot}}/operator/button-code">
|
||||||
{{l10n "leftMenu.client_gen_button"}}
|
{{l10n "leftMenu.client_gen_button"}}
|
||||||
</a>
|
</a>
|
||||||
{{l10n "admin.content.client_gen_button"}}
|
{{l10n "admin.content.client_gen_button"}}
|
||||||
|
Loading…
Reference in New Issue
Block a user