Ejemplo n.º 1
0
/**
 * Initialize visitor tracknig.
 *
 * Triggers {@link \Mibew\EventDispatcher\Events::VISITOR_CREATE} event.
 *
 * @param string $entry The page the visitor came from to the page with
 *   tracking code.
 * @param string $referer The page where tracking code is placed.
 * @return int ID of the visitor.
 */
function track_visitor_start($entry, $referer)
{
    $visitor = visitor_from_request();
    $db = Database::getInstance();
    $db->query("INSERT INTO {sitevisitor} ( " . "userid, username, firsttime, lasttime, entry,details " . ") VALUES ( " . ":userid, :username, :now, :now, :entry, :details " . ")", array(':userid' => $visitor['id'], ':username' => $visitor['name'], ':now' => time(), ':entry' => $entry, ':details' => track_build_details()));
    $id = $db->insertedId();
    if ($id) {
        track_visit_page($id, $referer);
    }
    $args = array('visitor' => track_get_visitor_by_id($id));
    EventDispatcher::getInstance()->triggerEvent(Events::VISITOR_CREATE, $args);
    return $id ? $id : 0;
}
Ejemplo n.º 2
0
function store_message($name, $email, $info, $message, $groupid, $referrer)
{
    global $state_left, $current_locale, $kind_for_agent, $kind_user;
    $remoteHost = get_remote_host();
    $userbrowser = $_SERVER['HTTP_USER_AGENT'];
    $visitor = visitor_from_request();
    $link = connect();
    $thread = create_thread($groupid, $name, $remoteHost, $referrer, $current_locale, $visitor['id'], $userbrowser, $state_left, $link);
    if ($referrer) {
        post_message_($thread['threadid'], $kind_for_agent, getstring2('chat.came.from', array($referrer)), $link);
    }
    if ($email) {
        post_message_($thread['threadid'], $kind_for_agent, getstring2('chat.visitor.email', array($email)), $link);
    }
    if ($info) {
        post_message_($thread['threadid'], $kind_for_agent, getstring2('chat.visitor.info', array($info)), $link);
    }
    post_message_($thread['threadid'], $kind_user, $message, $link, $name);
    mysql_close($link);
}
Ejemplo n.º 3
0
    /**
     * Starts the chat.
     *
     * @param Request $request Incoming request.
     * @return string|\Symfony\Component\HttpFoundation\RedirectResponse
     *   Rendered page content or a redirect response.
     * @todo Split the action into pieces.
     */
    public function startAction(Request $request)
    {
        // Check if we should force the user to use SSL
        $ssl_redirect = $this->sslRedirect($request);
        if ($ssl_redirect !== false) {
            return $ssl_redirect;
        }

        // Initialize client side application
        $this->getAssetManager()->attachJs('js/compiled/chat_app.js');

        $thread = null;
        // Try to get thread from the session
        if (isset($_SESSION[SESSION_PREFIX . 'threadid'])) {
            $thread = Thread::reopen($_SESSION[SESSION_PREFIX . 'threadid']);
        }

        // Create new thread
        if (!$thread) {
            // Load group info
            $group_id = '';
            $group_name = '';
            $group = null;
            if (Settings::get('enablegroups') == '1') {
                $group_id = $request->query->get('group');
                if (!preg_match("/^\d{1,10}$/", $group_id)) {
                    $group_id = false;
                }

                if ($group_id) {
                    $group = group_by_id($group_id);
                    if (!$group) {
                        $group_id = false;
                    } else {
                        $group_name = get_group_name($group);
                    }
                }
            }

            // Get operator code
            $operator_code = $request->query->get('operator_code');
            if (!preg_match("/^[A-z0-9_]+$/", $operator_code)) {
                $operator_code = false;
            }

            // Get visitor info
            $visitor = visitor_from_request();
            $info = $request->query->get('info');
            $email = $request->query->get('email');

            // Get referrer
            $referrer = $request->query->get('url', $request->headers->get('referer'));
            if ($request->query->get('referrer')) {
                $referrer .= "\n" . $request->query->get('referrer');
            }

            // Check if there are online operators
            if (!has_online_operators($group_id)) {
                // Display leave message page
                $page = array_merge_recursive(
                    setup_logo($group),
                    setup_leavemessage(
                        $visitor['name'],
                        $email,
                        $group_id,
                        $info,
                        $referrer
                    )
                );
                $page['leaveMessageOptions'] = $page['leaveMessage'];

                $this->getAssetManager()->attachJs(
                    $this->startJsApplication($request, $page),
                    AssetManagerInterface::INLINE,
                    1000
                );

                return $this->render('chat', $page);
            }

            // Get invitation info
            if (Settings::get('enabletracking') && !empty($_SESSION[SESSION_PREFIX . 'visitorid'])) {
                $invitation_state = invitation_state($_SESSION[SESSION_PREFIX . 'visitorid']);
                $visitor_is_invited = $invitation_state['invited'];
            } else {
                $visitor_is_invited = false;
            }

            // Get operator info
            $requested_operator = false;
            if ($operator_code) {
                $requested_operator = operator_by_code($operator_code);
            }

            // Check if survey should be displayed
            if (Settings::get('enablepresurvey') == '1' && !$visitor_is_invited && !$requested_operator) {
                // Display prechat survey
                $page = array_merge_recursive(
                    setup_logo($group),
                    setup_survey(
                        $visitor['name'],
                        $email,
                        $group_id,
                        $info,
                        $referrer
                    )
                );
                $page['surveyOptions'] = $page['survey'];

                $this->getAssetManager()->attachJs(
                    $this->startJsApplication($request, $page),
                    AssetManagerInterface::INLINE,
                    1000
                );

                return $this->render('chat', $page);
            }

            // Start chat thread
            $thread = chat_start_for_user(
                $group_id,
                $requested_operator,
                $visitor['id'],
                $visitor['name'],
                $referrer,
                $info
            );
        }
        $path_args = array(
            'thread_id' => intval($thread->id),
            'token' => urlencode($thread->lastToken),
        );

        $chat_style_name = $request->query->get('style');
        if (preg_match("/^\w+$/", $chat_style_name)) {
            $path_args['style'] = $chat_style_name;
        }

        return $this->redirect($this->generateUrl('chat_user', $path_args));
    }
Ejemplo n.º 4
0
    /**
     * Process submitted leave message form.
     *
     * Send message to operator email and create special meil thread.
     * @param array $args Associative array of arguments. It must contains the
     *   following keys:
     *    - 'threadId': for this function this param equals to null;
     *    - 'token': for this function this param equals to null;
     *    - 'name': string, user name;
     *    - 'email': string, user email;
     *    - 'message': string, user message;
     *    - 'info': string, some info about user;
     *    - 'referrer': string, page user came from;
     *    - 'captcha': string, captcha value;
     *    - 'groupId': selected group id.
     *
     * @throws \Mibew\RequestProcessor\ThreadProcessorException Can throw an
     *   exception if captcha or email is wrong.
     */
    protected function apiProcessLeaveMessage($args)
    {
        // Check captcha
        if (Settings::get('enablecaptcha') == '1' && can_show_captcha()) {
            $captcha = $args['captcha'];
            $original = isset($_SESSION[SESSION_PREFIX . 'mibew_captcha'])
                ? $_SESSION[SESSION_PREFIX . 'mibew_captcha']
                : '';
            unset($_SESSION[SESSION_PREFIX . 'mibew_captcha']);
            if (empty($original) || empty($captcha) || $captcha != $original) {
                throw new ThreadProcessorException(
                    getlocal('The letters you typed don\'t match the letters that were shown in the picture.'),
                    ThreadProcessorException::ERROR_WRONG_CAPTCHA
                );
            }
        }

        // Get form fields
        $email = $args['email'];
        $name = $args['name'];
        $message = $args['message'];
        $info = $args['info'];
        $referrer = $args['referrer'];

        if (!MailUtils::isValidAddress($email)) {
            throw new ThreadProcessorException(
                wrong_field("Your email"),
                ThreadProcessorException::ERROR_WRONG_EMAIL
            );
        }

        // Verify group id
        $group_id = '';
        if (Settings::get('enablegroups') == '1') {
            if (preg_match("/^\d{1,8}$/", $args['groupId']) != 0) {
                $group = group_by_id($args['groupId']);
                if ($group) {
                    $group_id = $args['groupId'];
                }
            }
        }

        // Create thread for left message
        $remote_host = get_remote_host();
        $user_browser = $_SERVER['HTTP_USER_AGENT'];
        $visitor = visitor_from_request();

        // Get message locale
        $message_locale = Settings::get('left_messages_locale');
        if (!locale_is_available($message_locale)) {
            $message_locale = get_home_locale();
        }

        // Create thread
        $thread = new Thread();
        $thread->groupId = $group_id;
        $thread->userName = $name;
        $thread->remote = $remote_host;
        $thread->referer = $referrer;
        $thread->locale = get_current_locale();
        $thread->userId = $visitor['id'];
        $thread->userAgent = $user_browser;
        $thread->state = Thread::STATE_LEFT;
        $thread->closed = time();
        $thread->save();

        // Send some messages
        if ($referrer) {
            $thread->postMessage(
                Thread::KIND_FOR_AGENT,
                getlocal('Vistor came from page {0}', array($referrer), get_current_locale(), true)
            );
        }
        if ($email) {
            $thread->postMessage(
                Thread::KIND_FOR_AGENT,
                getlocal('E-Mail: {0}', array($email), get_current_locale(), true)
            );
        }
        if ($info) {
            $thread->postMessage(
                Thread::KIND_FOR_AGENT,
                getlocal('Info: {0}', array($info), get_current_locale(), true)
            );
        }
        $thread->postMessage(Thread::KIND_USER, $message, array('name' => $name));

        // Get email for message
        $inbox_mail = get_group_email($group_id);

        if (empty($inbox_mail)) {
            $inbox_mail = Settings::get('email');
        }

        // Send email
        if ($inbox_mail) {
            // Prepare message to send by email
            $mail_template = MailTemplate::loadByName('leave_message', $message_locale);
            if (!$mail_template) {
                trigger_error(
                    'Cannot send e-mail because "leave_message" mail template cannot be loaded.',
                    E_USER_WARNING
                );

                return;
            }

            $subject = $mail_template->buildSubject(array($args['name']));
            $body = $mail_template->buildBody(array(
                $args['name'],
                $email,
                $message,
                ($info ? $info . "\n" : ""),
            ));

            // Send
            $this->getMailerFactory()->getMailer()->send(
                MailUtils::buildMessage($inbox_mail, $email, $subject, $body)
            );
        }
    }
Ejemplo n.º 5
0
 }
 if (!$thread) {
     $groupid = "";
     $groupname = "";
     if ($settings['enablegroups'] == '1') {
         $groupid = verifyparam("group", "/^\\d{1,10}\$/", "");
         if ($groupid) {
             $group = group_by_id($groupid);
             if (!$group) {
                 $groupid = "";
             } else {
                 $groupname = get_group_name($group);
             }
         }
     }
     $visitor = visitor_from_request();
     if (isset($_POST['survey']) && $_POST['survey'] == 'on') {
         $firstmessage = getparam("message");
         $info = getparam("info");
         $email = getparam("email");
         $referrer = urldecode(getparam("referrer"));
         if ($settings["surveyaskcaptcha"] == "1") {
             $captcha = getparam('captcha');
             $original = isset($_SESSION["mibew_captcha"]) ? $_SESSION["mibew_captcha"] : "";
             $survey_captcha_failed = empty($original) || empty($captcha) || $captcha != $original;
             unset($_SESSION['mibew_captcha']);
         }
         if ($settings['usercanchangename'] == "1" && isset($_POST['name'])) {
             $newname = getparam("name");
             if ($newname != $visitor['name']) {
                 $data = strtr(base64_encode(myiconv($mibew_encoding, "utf-8", $newname)), '+/=', '-_,');