예제 #1
0
 /**
  * Generates JavaScript code that starts client side application.
  *
  * @param Request $request Incoming request.
  * @param array $operator Current operator.
  * @return string JavaScript code that starts "users" client side
  *   application.
  */
 protected function startJsApplication(Request $request, $operator)
 {
     // Load dialogs style options
     $chat_style = new ChatStyle(ChatStyle::getCurrentStyle());
     $chat_style_config = $style_config = $chat_style->getConfigurations();
     // Load page style options
     $page_style_config = $style_config = $this->getStyle()->getConfigurations();
     return sprintf('jQuery(document).ready(function() {Mibew.Application.start(%s);});', json_encode(array('server' => array('url' => $this->generateUrl('users_update'), 'requestsFrequency' => Settings::get('updatefrequency_operator')), 'agent' => array('id' => $operator['operatorid']), 'page' => array('mibewBasePath' => $request->getBasePath(), 'mibewBaseUrl' => $request->getBaseUrl(), 'showOnlineOperators' => Settings::get('showonlineoperators') == '1', 'showVisitors' => Settings::get('enabletracking') == '1', 'showPopup' => Settings::get('enablepopupnotification') == '1', 'threadTag' => $page_style_config['users']['thread_tag'], 'visitorTag' => $page_style_config['users']['visitor_tag'], 'agentLink' => $request->getBaseUrl() . '/operator/chat', 'geoLink' => Settings::get('geolink'), 'trackedLink' => $request->getBaseUrl() . '/operator/history/user-track', 'banLink' => $request->getBaseUrl() . '/operator/ban', 'inviteLink' => $request->getBaseUrl() . '/operator/invite', 'chatWindowParams' => $chat_style_config['chat']['window'], 'geoWindowParams' => Settings::get('geolinkparams'), 'trackedUserWindowParams' => $page_style_config['tracked']['user_window'], 'trackedVisitorWindowParams' => $page_style_config['tracked']['visitor_window'], 'banWindowParams' => $page_style_config['ban']['window'], 'inviteWindowParams' => $chat_style_config['chat']['window']))));
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 protected function getStyle()
 {
     if (is_null($this->style)) {
         $this->style = $this->prepareStyle(new ChatStyle(ChatStyle::getDefaultStyle()));
     }
     return $this->style;
 }
예제 #3
0
 /**
  * Generates a JavaScript file with popup CSS file loader.
  *
  * @param Request $request
  * @return JsonResponse
  */
 public function loadPopupStyleAction(Request $request)
 {
     $style_name = $request->attributes->get('style');
     if (!$style_name) {
         $style_name = ChatStyle::getDefaultStyle();
     }
     $style = new ChatStyle($style_name);
     $configs = $style->getConfigurations();
     $response = new JsonResponse();
     if ($configs['chat']['iframe']['css']) {
         $generator = $this->getAssetManager()->getUrlGenerator();
         $css = $generator->generate($style->getFilesPath() . '/' . $configs['chat']['iframe']['css'], UrlGeneratorInterface::ABSOLUTE_URL);
         $response->setData($css);
         $response->setCallback('Mibew.Utils.loadStyleSheet');
     }
     return $response;
 }
예제 #4
0
 /**
  * Processes submitting of the form which is generated in
  * {@link \Mibew\Controller\Settings\CommonController::showFormAction()}
  * method.
  *
  * @param Request $request Incoming request.
  * @return string Rendered page content.
  * @throws BadRequestException If one or more parameters of the request have
  *   wrong format.
  */
 public function submitFormAction(Request $request)
 {
     csrf_check_token($request);
     $errors = array();
     $params = array();
     $params['email'] = $request->request->get('email');
     $params['title'] = $request->request->get('title');
     $params['logo'] = $request->request->get('logo');
     $params['hosturl'] = $request->request->get('hosturl');
     $params['usernamepattern'] = $request->request->get('usernamepattern');
     $params['chattitle'] = $request->request->get('chattitle');
     $params['geolink'] = $request->request->get('geolink');
     $params['geolinkparams'] = $request->request->get('geolinkparams');
     $params['cron_key'] = $request->request->get('cronkey');
     $send_key = $request->request->get('sendmessagekey');
     if (!preg_match("/^c?enter\$/", $send_key)) {
         throw new BadRequestException('Wrong format of "sendmessagekey" field.');
     }
     $params['sendmessagekey'] = $send_key;
     $params['left_messages_locale'] = $request->request->get('leftmessageslocale');
     if (!in_array($params['left_messages_locale'], get_available_locales())) {
         $params['left_messages_locale'] = get_home_locale();
     }
     if ($params['email'] && !MailUtils::isValidAddress($params['email'])) {
         $errors[] = getlocal('Enter a valid email address');
     }
     if ($params['geolinkparams']) {
         foreach (explode(',', $params['geolinkparams']) as $one_param) {
             $wrong_param = !preg_match("/^\\s*(toolbar|scrollbars|location|status|menubar|width|height|resizable)=\\d{1,4}\$/", $one_param);
             if ($wrong_param) {
                 $errors[] = "Wrong link parameter: \"{$one_param}\", " . "should be one of 'toolbar, scrollbars, location, " . "status, menubar, width, height or resizable'";
             }
         }
     }
     if (preg_match("/^[0-9A-Za-z]*\$/", $params['cron_key']) == 0) {
         $errors[] = getlocal('Use only Latin letters(upper and lower case) and numbers in cron key.');
     }
     // Load styles configs
     $chat_style = $request->request->get('chat_style', ChatStyle::getDefaultStyle());
     $chat_style_list = ChatStyle::getAvailableStyles();
     if (!in_array($chat_style, $chat_style_list)) {
         $chat_style = $chat_style_list[0];
     }
     $page_style = $request->request->get('page_style', PageStyle::getDefaultStyle());
     $page_style_list = PageStyle::getAvailableStyles();
     if (!in_array($page_style, $page_style_list)) {
         $page_style = $page_style_list[0];
     }
     if (Settings::get('enabletracking')) {
         $invitation_style = $request->request->get('invitation_style', InvitationStyle::getDefaultStyle());
         $invitation_style_list = InvitationStyle::getAvailableStyles();
         if (!in_array($invitation_style, $invitation_style_list)) {
             $invitation_style = $invitation_style_list[0];
         }
     }
     if (count($errors) != 0) {
         $request->attributes->set('errors', $errors);
         // The form should be rebuild. Invoke appropriate action.
         return $this->showFormAction($request);
     }
     // Update system settings
     foreach ($params as $key => $value) {
         Settings::set($key, $value);
     }
     // Update styles params
     ChatStyle::setDefaultStyle($chat_style);
     PageStyle::setDefaultStyle($page_style);
     if (Settings::get('enabletracking')) {
         InvitationStyle::setDefaultStyle($invitation_style);
     }
     // Redirect the user to the same page using GET method
     $redirect_to = $this->generateUrl('settings_common', array('stored' => true));
     return $this->redirect($redirect_to);
 }
예제 #5
0
파일: chat.php 프로젝트: aburakovskiy/mibew
/**
 * Prepare some data for chat for both user and operator
 *
 * @param Thread $thread thread object
 * @return array Array of chat view data
 */
function setup_chatview(Thread $thread)
{
    $data = prepare_chat_app_data();
    // Get group info
    if (!empty($thread->groupId)) {
        $group = group_by_id($thread->groupId);
        $group = get_top_level_group($group);
    } else {
        $group = array();
    }
    // Create some empty arrays
    $data['chat'] = array('messageForm' => array(), 'links' => array(), 'windowsParams' => array());
    // Set thread params
    $data['chat']['thread'] = array('id' => $thread->id, 'token' => $thread->lastToken, 'agentId' => $thread->agentId, 'userId' => $thread->userId);
    $data['page.title'] = empty($group['vcchattitle']) ? Settings::get('chattitle') : $group['vcchattitle'];
    $data['chat']['page'] = array('title' => $data['page.title']);
    // Setup logo
    $data = array_merge_recursive($data, setup_logo($group));
    // Set enter key shortcut
    if (Settings::get('sendmessagekey') == 'enter') {
        $data['chat']['messageForm']['ignoreCtrl'] = true;
    } else {
        $data['chat']['messageForm']['ignoreCtrl'] = false;
    }
    // Load dialogs style options
    $chat_style = new ChatStyle(ChatStyle::getCurrentStyle());
    $style_config = $chat_style->getConfigurations();
    $data['chat']['windowsParams']['mail'] = $style_config['mail']['window'];
    // Load core style options
    $page_style = new PageStyle(PageStyle::getCurrentStyle());
    $style_config = $page_style->getConfigurations();
    $data['chat']['windowsParams']['history'] = $style_config['history']['window'];
    $data['startFrom'] = 'chat';
    return $data;
}
예제 #6
0
 /**
  * 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 = $this->getOperator();
     $page = array('errors' => array());
     $image_locales_map = $this->getImageLocalesMap(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('-from general settings-');
     $style = $request->query->get('style', '');
     if ($style && !in_array($style, $style_list)) {
         $style = '';
     }
     $invitation_style_list = InvitationStyle::getAvailableStyles();
     $invitation_style_list[''] = getlocal('-from general settings-');
     $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("No such group");
         $group_id = false;
     }
     $show_host = $request->query->get('hostname') == 'on';
     $force_secure = $request->query->get('secure') == 'on';
     $mod_security = $request->query->get('modsecurity') == 'on';
     $force_windows = $request->query->get('forcewindows') == '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';
     $button_generator_options = array('chat_style' => $style, 'group_id' => $group_id, 'show_host' => $show_host, 'force_secure' => $force_secure, 'mod_security' => $mod_security, 'prefer_iframe' => !$force_windows);
     if ($operator_code) {
         $button_generator = new OperatorCodeFieldGenerator($this->getRouter(), $this->getAssetManager()->getUrlGenerator(), $button_generator_options);
     } elseif ($generate_button) {
         // Make sure locale exists
         if (!$lang || !in_array($lang, $image_locales)) {
             $lang = in_array(get_current_locale(), $image_locales) ? get_current_locale() : $image_locales[0];
         }
         $button_generator = new ImageButtonGenerator($this->getRouter(), $this->getAssetManager()->getUrlGenerator(), $button_generator_options);
         // Set generator-specific options
         $button_generator->setOption('image', $image);
     } else {
         // Make sure locale exists
         if (!$lang || !in_array($lang, $locales_list)) {
             $lang = in_array(get_current_locale(), $locales_list) ? get_current_locale() : $locales_list[0];
         }
         $button_generator = new TextButtonGenerator($this->getRouter(), $this->getAssetManager()->getUrlGenerator(), $button_generator_options);
         // Set generator-specific options
         $button_generator->setOption('caption', getlocal('Click to chat'));
     }
     // Set verified locale code to a button generator
     $button_generator->setOption('locale', $lang);
     $page['buttonCode'] = $button_generator->generate();
     $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'] = $this->getGroupsList();
     $page['availableCodeTypes'] = array('button' => getlocal('button'), 'operator_code' => getlocal('operator code field'), 'text_link' => getlocal('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['formforcewindows'] = $force_windows;
     $page['enabletracking'] = Settings::get('enabletracking');
     $page['operator_code'] = $operator_code;
     $page['generateButton'] = $generate_button;
     $page['title'] = getlocal("Button HTML code generation");
     $page['menuid'] = "getcode";
     $page = array_merge($page, prepare_menu($operator));
     return $this->render('button_code', $page);
 }
예제 #7
0
 /**
  * Gets the style options string for the chat popup.
  *
  * @return array
  */
 protected function getPopupStyle()
 {
     $defaults = array('width' => 640, 'height' => 480, 'resizable' => true);
     $style_name = $this->getOption('chat_style');
     if (!$style_name) {
         return $defaults + array('styleLoader' => $this->generateUrl('chat_user_popup_style'));
     }
     $chat_style = new ChatStyle($style_name);
     $chat_configs = $chat_style->getConfigurations();
     // Intersection is used to limit style options to keys from the defaults
     // array.
     return array_intersect_key($chat_configs['chat']['window'] + $defaults, $defaults) + array('styleLoader' => $this->generateUrl('chat_user_popup_style', array('style' => $style_name)));
 }