src/Social/UserBundle/Controller/RegistrationController.php line 114

Open in your IDE?
  1. <?php
  2. namespace Social\UserBundle\Controller;
  3. use DateTime;
  4. use GuzzleHttp\Exception\GuzzleException;
  5. use Psr\Log\LoggerInterface;
  6. use Social\CreditsBundle\Entity\CreditUserHistoryEntity;
  7. use Social\FrontendBundle\Service\ConversionManager;
  8. use Social\InternalBundle\Entity\AdminAlertsEntity;
  9. use Social\InternalBundle\Entity\EmailSiteSource;
  10. use Social\InternalBundle\Entity\PackagesList;
  11. use Social\InternalBundle\Entity\SentsioImportHistory;
  12. use Social\InternalBundle\Service\LocationService;
  13. use Social\UserBundle\Form\UserType;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use FOS\UserBundle\Model\UserManagerInterface;
  16. use FOS\UserBundle\Form\Factory\FactoryInterface;
  17. use Symfony\Component\Form\Form;
  18. use Symfony\Component\HttpClient\HttpClient;
  19. use Symfony\Component\Translation\TranslatorInterface;
  20. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  21. use FOS\UserBundle\Controller\RegistrationController as BaseRegistrationController;
  22. use FOS\UserBundle\Event\FilterUserResponseEvent;
  23. use FOS\UserBundle\Event\FormEvent;
  24. use FOS\UserBundle\Event\GetResponseUserEvent;
  25. use FOS\UserBundle\FOSUserEvents;
  26. use GuzzleHttp\Client;
  27. use Social\FrontendBundle\Form\NewsletterType;
  28. use Social\InternalBundle\Entity\EmailInviteImport;
  29. use Social\InternalBundle\Entity\EmailList;
  30. use Social\InternalBundle\Entity\TrafficPoll\Conversions;
  31. use Social\InternalBundle\Entity\TrafficPoll\UrlParameters;
  32. use Social\InternalBundle\Entity\TrafficPool;
  33. use Social\UserBundle\Entity\User;
  34. use Social\UserBundle\Entity\UserComponents\UserSignupPollData;
  35. use Symfony\Component\Form\FormError;
  36. use Symfony\Component\Form\FormErrorIterator;
  37. use Symfony\Component\HttpFoundation\JsonResponse;
  38. use Symfony\Component\HttpFoundation\ParameterBag;
  39. use Symfony\Component\HttpFoundation\RedirectResponse;
  40. use Symfony\Component\HttpFoundation\Request;
  41. use Symfony\Component\HttpFoundation\Response;
  42. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  43. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  44. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  45. /**
  46.  * Class RegistrationController
  47.  *
  48.  * @package Social\UserBundle\Controller
  49.  */
  50. class RegistrationController extends BaseRegistrationController
  51. {
  52.     protected $eventDispatcher;
  53.     protected $formFactory;
  54.     protected $userManager;
  55.     protected $tokenStorage;
  56.     /** @var LocationService */
  57.     private $locationService;
  58.     /**
  59.      * @var LoggerInterface
  60.      */
  61.     private $subscriptionLogger;
  62.     /**
  63.      * @var ConversionManager
  64.      */
  65.     private $conversionManager;
  66.     public function __construct(
  67.         EventDispatcherInterface $eventDispatcher,
  68.         FactoryInterface $formFactory,
  69.         UserManagerInterface $userManager,
  70.         TokenStorageInterface $tokenStorage,
  71.         LocationService $locationService,
  72.         LoggerInterface $subscriptionLogger,
  73.         ConversionManager $conversionManager
  74.     ) {
  75.         $this->eventDispatcher $eventDispatcher;
  76.         $this->formFactory     $formFactory;
  77.         $this->userManager     $userManager;
  78.         $this->tokenStorage    $tokenStorage;
  79.         parent::__construct($eventDispatcher$formFactory$userManager$tokenStorage);
  80.         $this->locationService $locationService;
  81.         $this->subscriptionLogger $subscriptionLogger;
  82.         $this->conversionManager $conversionManager;
  83.     }
  84.     /**
  85.      * @param Request $request
  86.      *
  87.      * @return JsonResponse|RedirectResponse|Response|null
  88.      * @throws GuzzleException
  89.      */
  90.     public function indexAction(Request $request)
  91.     {
  92.         $userIP $request->getClientIp();
  93.         $locale $request->getLocale();
  94.         /** @var \Sentry\Client $sentry */
  95.         $sentry $this->get('sentry.client');
  96.         try {
  97.             if ($this->getUser()) {
  98.                 if ($this->isGranted('ROLE_SONATA_ADMIN')) {
  99.                     return $this->redirect($this->get('router')->generate('sonata_admin_dashboard'));
  100.                 }
  101.                 return $this->redirect($this->get('router')->generate('social_frontend_account'));
  102.             }
  103.             /** @var $userManager UserManagerInterface */
  104.             $userManager  $this->container->get('fos_user.user_manager');
  105.             $socialUserManager $this->container->get('social_user.user_manager');
  106.             /** @var $dispatcher EventDispatcherInterface */
  107.             $dispatcher $this->container->get('event_dispatcher');
  108.             $em $this->getDoctrine()->getManager();
  109.             /** @var User $user */
  110.             $user $userManager->createUser();
  111.             $user->setEnabled(true); # will rely on confirmed
  112.             $event = new GetResponseUserEvent($user$request);
  113.             $dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE$event);
  114.             if (null !== $event->getResponse()) {
  115.                 return $event->getResponse();
  116.             }
  117.             $form $this->createForm(UserType::class, $user, [
  118.                 'include_birthday' => true,
  119.                 'include_agree'    => true
  120.             ]);
  121.             $form->setData($user);
  122.             if ('POST' === $request->getMethod()) {
  123.                 $user->setEmail('');
  124.                 $form->handleRequest($request);
  125.                 $requestParams $request->get('user');
  126.                 $email $requestParams['email'];
  127.                 $password $requestParams['password'];
  128.                 if($password == null || $password == '') {
  129.                     $form->addError(new FormError($this->get('translator')->trans('A password is required!')));
  130.                 }
  131.                 if (!filter_var($emailFILTER_VALIDATE_EMAIL)) {
  132.                     $form->addError(new FormError($this->get('translator')->trans('Invalid email')));
  133.                 }
  134.                 if ($email !== $requestParams['email_repeat']) {
  135.                     $form->addError(new FormError($this->get('translator')->trans('Emails are not the same')));
  136.                 }
  137.                 
  138.                 if ($form->isValid()) {
  139.                     try {
  140.                         $user->setRoles(['ROLE_USER']);
  141.                         $user->setLastRegistrationStep(4);
  142.                         $email $this->replace_spec_char($user->getEmail());
  143.                         $user->setEmail($email);
  144.                         $user->setCanCommentOrChat(false);
  145.                         // Check if user is in email traffic to set if it can comment and send chat message
  146.                         $emailTrafficUserExists $this->getDoctrine()->getRepository(EmailList::class)->findOneBy(['email' => $user->getEmail()]);
  147.                         if ($emailTrafficUserExists instanceof EmailList) {
  148.                             $user->setCanCommentOrChat(true);
  149.                             if ($emailTrafficUserExists->getAddedInSentsio()) {
  150.                                 $this->unsubscribeEmailListInSentsio($emailTrafficUserExists$sentry);
  151.                             }
  152.                         }
  153.                         $dateTime = new DateTime('now');
  154.                         $pusherInstanceService $this->get('social.pusher_initializer')->initialize();
  155.                         if ($user->hasRole(User::ROLE_USER)) {
  156.                             $staffUsers $em->getRepository(User::class)->getStaffUsers();
  157.                             foreach ($staffUsers as $staffUser) {
  158.                                 if ($staffUser instanceof User) {
  159.                                     $adminAlert = new AdminAlertsEntity();
  160.                                     $adminAlert->setFromUser($user);
  161.                                     $adminAlert->setToUser($staffUser);
  162.                                     $adminAlert->setMessage($user->getUsername() . ' signed up.');
  163.                                     $adminAlert->setType(AdminAlertsEntity::ALERT_TYPE_SIGNUP);
  164.                                     $adminAlert->setIsNew(true);
  165.                                     $adminAlert->setIsRead(false);
  166.                                     $adminAlert->setIsDeleted(false);
  167.                                     $em->persist($adminAlert);
  168.                                     $pusherInstanceService->trigger(
  169.                                         'farmer_notifications_' $staffUser->getId(),
  170.                                         'farmer_notifications',
  171.                                         [
  172.                                             'id' => $adminAlert->getId(),
  173.                                             'username' => $user->getUsername(),
  174.                                             'to_user' => 'SignUp',
  175.                                             'picture' => '<i class="fas fa-sign-in"></i>',
  176.                                             'action' => 'Sign up',
  177.                                             'type' => 'Sign up',
  178.                                             'message' => 'User ' $user->getUsername() . 'signed up',
  179.                                             'time' => $dateTime->format('Y-m-d H:i:s'),
  180.                                             'timestamp' => $dateTime->getTimestamp(),
  181.                                             'action_key' => AdminAlertsEntity::ALERT_TYPE_SIGNUP,
  182.                                             'sound' => $this->get('social.alert_manager')->getAlertSoundSetting(AdminAlertsEntity::ALERT_TYPE_SIGNUP$staffUser)
  183.                                         ]
  184.                                     );
  185.                                 }
  186.                             }
  187.                         }
  188.                         $userManager->updateUser($user);
  189.                         $extendedConfirmationHours = (int)$this->container->getParameter('user_registration_account_activation_time_limit');
  190.                         $user->setInterestedIn($user->getGender() == ? [1] : [0]);
  191.                         $user->setExtendPeriodSignupConfirmation((($extendedConfirmationHours 0) ? $extendedConfirmationHours 24));
  192.                         $pinCode $socialUserManager->generatePinCode();
  193.                         $user->setPinCode($pinCode);
  194.                         $em->persist($user);
  195.                         $em->flush();
  196.                         $this->subscriptionLogger->info("Created User with ID " $user->getId());
  197.                         $localeAdded false;
  198.                         $cookies $request->cookies;
  199.                         $trafficPollCookies $cookies->get('tfpr');
  200.                         $emailLists = [];
  201.                         // Traffic poll cookies - array
  202.                         if (isset($trafficPollCookies['pollId'])) {
  203.                             $pollId $trafficPollCookies['pollId'];
  204.                             /** @var TrafficPool $trafficPollEntity */
  205.                             $trafficPollEntity $this->getDoctrine()->getRepository(TrafficPool::class)->find($pollId);
  206.                             $this->subscriptionLogger->info("IN IF with trafficPollEntity = " $trafficPollEntity->getId());
  207.                             if ($trafficPollEntity->getId()) {
  208.                                 $this->get('social_internal.boot_action_manager')->createBootLiveSchedule($request$trafficPollEntity$user);
  209.                                 if ($trafficPollEntity->getPackageList()) {
  210.                                     $packageName $trafficPollEntity->getPackageList()->getName();
  211.                                     $credits $trafficPollEntity->getPackageList()->getCredits();
  212.                                     $user->setPackageName($packageName);
  213.                                     $user->setCredits($credits);
  214.                                     $user->setHasAgreedToWaiveRights(true);
  215.                                     $em->persist($user);
  216.                                     $em->flush();
  217.                                     $this->subscriptionLogger->info("New credits of " $user->getId() . " is " $user->getCredits());
  218.                                     $this->addCreditUserHistory($user$trafficPollEntity->getPackageList());
  219.                                 }
  220.                                 if ($trafficPollEntity->getPollType() == TrafficPool::POLL_TYPE_USER_PAGE ||
  221.                                     $trafficPollEntity->getPollType() == TrafficPool::POLL_TYPE_SEARCH) {
  222.                                     $user->setCanCommentOrChat(true);
  223.                                     $em->persist($user);
  224.                                     $em->flush();
  225.                                     $this->subscriptionLogger->info('pollType = ' $trafficPollEntity->getPollType());
  226.                                     if (!$trafficPollEntity->isAddInEmailList()) {
  227.                                         $contactEmailList $em->getRepository(EmailList::class)->findOneBy(['email' => $user->getEmail()]);
  228.                                     } else {
  229.                                         $contactEmailList = new EmailList();
  230.                                         $contactEmailList->setEmail($user->getEmail());
  231.                                         $contactEmailList->setSkype(null);
  232.                                         $contactEmailList->setNickname($user->getUsername());
  233.                                         $contactEmailList->setFirstName($user->getFirstName());
  234.                                         $contactEmailList->setLastName($user->getLastName());
  235.                                         $contactEmailList->setEmailLanguage($user->getLanguage());
  236.                                         try {
  237.                                             if ($user->getNewLocation() !== null) {
  238.                                                 $contactEmailList->setLocation($user->getNewLocation()->__toString());
  239.                                             } else {
  240.                                                 $contactEmailList->setLocation('N/A');
  241.                                             }
  242.                                         } catch (\Exception $exception) {
  243.                                             $contactEmailList->setLocation('N/A2');
  244.                                             $sentry->captureException($exception);
  245.                                         }
  246.                                         $contactEmailList->setGender($user->getGender());
  247.                                         $contactEmailList->setMoreDetails('User traffic pool - ' $trafficPollEntity->getId());
  248.                                         $contactEmailList->setDiscussion('');
  249.                                         $contactEmailList->setUserDificil(false);
  250.                                         if (isset($trafficPollCookies['uts']) && $trafficPollCookies['uts'] !== null && $trafficPollCookies['uts'] > 0) {
  251.                                             $emailSiteSourceEntity $em->getRepository(EmailSiteSource::class)->find((int)$trafficPollCookies['uts']);
  252.                                             if ($emailSiteSourceEntity instanceof EmailSiteSource) {
  253.                                                 $contactEmailList->setEmailSiteSource($emailSiteSourceEntity);
  254.                                             }
  255.                                         }
  256.                                         if (isset($trafficPollCookies['utf']) && $trafficPollCookies['utf'] !== null && $trafficPollCookies['utf'] > 0) {
  257.                                             $toUserId $em->getRepository(User::class)->find($trafficPollCookies['utf']);
  258.                                             $contactEmailList->setToUser($toUserId);
  259.                                         }
  260.                                         if (isset($trafficPollCookies['uth']) && $trafficPollCookies['uth'] !== null && $trafficPollCookies['uth'] > 0) {
  261.                                             $fromUserId $em->getRepository(User::class)->find($trafficPollCookies['uth']);
  262.                                             $contactEmailList->setFromUser($fromUserId);
  263.                                         }
  264.                                         // Setting profile sent
  265.                                         $trafficPoolUsers $trafficPollEntity->getPollUsers();
  266.                                         if ($trafficPoolUsers !== null && count($trafficPoolUsers) === 1) {
  267.                                             $contactEmailList->setProfileSent($trafficPoolUsers[0]);
  268.                                         }
  269.                                         $contactEmailList->setEmailObtainedFromFlag(EmailList::MAIL_OBTAINED_FROM_TRAFFIC_POOL_USER_PAGE);
  270.                                         $em->persist($contactEmailList);
  271.                                     }
  272.                                     if ($contactEmailList) {
  273.                                         $contactEmailList->setSignedUpUser($user);
  274.                                         $em->persist($contactEmailList);
  275.                                         $em->flush();
  276.                                         if ($contactEmailList->getFromUser() && $contactEmailList->getFromUser()->hasRole(User::ROLE_HSTAFF)) {
  277.                                             if ($contactEmailList->getFromUser() instanceof User) {
  278.                                                 $adminAlert = new AdminAlertsEntity();
  279.                                                 $adminAlert->setFromUser($user);
  280.                                                 $adminAlert->setToUser($contactEmailList->getFromUser());
  281.                                                 $adminAlert->setMessage($user->getUsername() . ' signed up.');
  282.                                                 $adminAlert->setType(AdminAlertsEntity::ALERT_TYPE_SIGNUP);
  283.                                                 $adminAlert->setIsNew(true);
  284.                                                 $adminAlert->setIsRead(false);
  285.                                                 $adminAlert->setIsDeleted(false);
  286.                                                 $em->persist($adminAlert);
  287.                                                 $em->flush($adminAlert);
  288.                                                 $pusherInstanceService->trigger(
  289.                                                     'farmer_notifications_' $contactEmailList->getFromUser()->getId(),
  290.                                                     'farmer_notifications',
  291.                                                     [
  292.                                                         'id' => $adminAlert->getId(),
  293.                                                         'username' => $user->getUsername(),
  294.                                                         'to_user' => 'SignUp',
  295.                                                         'picture' => '<i class="fas fa-sign-in"></i>',
  296.                                                         'action' => 'Sign up',
  297.                                                         'type' => 'Sign up',
  298.                                                         'message' => 'User ' $user->getUsername() . 'signed up',
  299.                                                         'time' => $dateTime->format('Y-m-d H:i:s'),
  300.                                                         'timestamp' => $dateTime->getTimestamp(),
  301.                                                         'action_key' => AdminAlertsEntity::ALERT_TYPE_SIGNUP,
  302.                                                         'sound' => $this->get('social.alert_manager')->getAlertSoundSetting(AdminAlertsEntity::ALERT_TYPE_SIGNUP$contactEmailList->getFromUser())
  303.                                                     ]
  304.                                                 );
  305.                                             }
  306.                                         }
  307.                                         $emailLists = [$contactEmailList];
  308.                                     }
  309.                                     $source $trafficPollEntity->getPollType() == TrafficPool::POLL_TYPE_USER_PAGE "SignUp UserPage - $pollId"SignUp SearchPage - $pollId";
  310.                                     if ($trafficPollEntity->getPackageList()) {
  311.                                         $socialUserManager->addUserPackageHistory($user$source$trafficPollEntity->getPackageList(), 'N/A'00);
  312.                                     }
  313.                                 }
  314.                                 // Getting parameters from traffic poll
  315.                                 $trafficPollParameters $trafficPollEntity->getUrlParameters();
  316.                                 /** @var UrlParameters $singleParam */
  317.                                 foreach ($trafficPollParameters as $singleParam) {
  318.                                     if (isset($trafficPollCookies[$singleParam->getkeyValue()])) {
  319.                                         $newTrafficTrackData = new UserSignupPollData();
  320.                                         $newTrafficTrackData->setUrlParamReference($singleParam);
  321.                                         $newTrafficTrackData->setPollReference($trafficPollEntity);
  322.                                         $newTrafficTrackData->setLabel($singleParam->getLabel());
  323.                                         $newTrafficTrackData->setUserReference($user);
  324.                                         $newTrafficTrackData->setUrlKey($singleParam->getkeyValue());
  325.                                         $newTrafficTrackData->setDataValue(
  326.                                             $trafficPollCookies[$singleParam->getkeyValue()]
  327.                                         );
  328.                                         $newTrafficTrackData->setCreatedAt(new \DateTime('now'));
  329.                                         $em->persist($newTrafficTrackData);
  330.                                         $em->flush();
  331.                                     }
  332.                                 }
  333.                                 if ($trafficPollEntity->getAutoSetLocation()) {
  334.                                     $this->subscriptionLogger->info('In getAutoSetLocation ');
  335.                                     /* Adding user location if we can */
  336.                                     $userLocationTrack $this->get('social_internal.ip_track_manager')->getLocationForIp($userIP);
  337.                                     $userLocation $this->get('social_internal.ip_track_manager')->getLocationFromDBForUserObject(
  338.                                         $userLocationTrack,
  339.                                         $locale
  340.                                     );
  341.                                     if ($userLocation != null) {
  342.                                         if (is_array($userLocation)) {
  343.                                             $user->setNewLocation($userLocation[0]);
  344.                                             $localeAdded true;
  345.                                         }
  346.                                     }
  347.                                 }
  348.                                 $conversions $trafficPollEntity->getConversions();
  349.                                 $this->conversionManager->triggerConversionPostbackForLP($trafficPollCookies$user$conversions);
  350.                                 if ($localeAdded) {
  351.                                     $this->subscriptionLogger->info('In localeAdded');
  352.                                 }
  353.                                 $historyApiip $this->locationService->generateLocationHistory($userIP$user$trafficPollEntity->getAutoSetLocation());
  354.                                 $this->locationService->postGenerateLocationHistory($historyApiip$locale);
  355.                                 if ($contactEmailList) {
  356.                                     $contactEmailList->setEmailLanguage($user->getLanguage());
  357.                                     $em->persist($contactEmailList);
  358.                                     $em->flush();
  359.                                 }
  360.                             }
  361.                         } else {
  362.                             $this->subscriptionLogger->info("IN ELSE");
  363.                             $emailLists $this->get('social_internal.email_list_manager')->findEmailListsForUser($user);
  364.                             $packageList $em->getRepository(PackagesList::class)->findOneBy(['name' => 'default']);
  365.                             $socialUserManager->addUserPackageHistory($user'SignUp Normal'$packageList'N/A'00);
  366.                             $this->subscriptionLogger->info("credits = " $packageList->getCredits());
  367.                             $user->setCredits($packageList->getCredits());
  368.                             $em->persist($user);
  369.                             $em->flush();
  370.                             $this->subscriptionLogger->info("New credits of " $user->getId() . " is " $user->getCredits());
  371.                             $this->addCreditUserHistory($user$packageList);
  372.                             /* Adding user location if we can */
  373.                             $userLocationTrack $this->get('social_internal.ip_track_manager')->getLocationForIp($userIP);
  374.                             $userLocation $this->get('social_internal.ip_track_manager')->getLocationFromDBForUserObject(
  375.                                 $userLocationTrack,
  376.                                 $locale
  377.                             );
  378.                             if ($userLocation != null) {
  379.                                 $this->subscriptionLogger->info("userLocation is " json_encode($userLocation));
  380.                                 if (is_array($userLocation)) {
  381.                                     $this->subscriptionLogger->info("In isArray userLocation is " $userLocation[0]->getId());
  382.                                     $user->setNewLocation($userLocation[0]);
  383.                                 }
  384.                             }
  385.                             $this->subscriptionLogger->info('credit history added for userID ' $user->getId());
  386.                             $historyApiip $this->locationService->generateLocationHistory($userIP$userfalse);
  387.                             $this->locationService->postGenerateLocationHistory($historyApiip$locale);
  388.                         }
  389.                         $this->subscriptionLogger->info('current credit history for userID ' $user->getCredits());
  390.                         $contactInvites $this->get('social_internal.contact_inviter_manager')->findContactInvitesForUser($user);
  391.                         /** @var EmailInviteImport $emailImportExists */
  392.                         $emailImportExists $em->getRepository('SocialInternalBundle:EmailInviteImport')->findOneBy(['email' => $user->getEmail()]);
  393.                         $this->subscriptionLogger->info("emailLists = " count($emailLists));
  394.                         $this->subscriptionLogger->info("contactInvites = " count($contactInvites));
  395.                         if ($emailImportExists) {
  396.                             $this->subscriptionLogger->info("In emailImportExists");
  397.                             $emailImportExists->setSignUpMade(true);
  398.                             $em->persist($emailImportExists);
  399.                             $em->flush();
  400.                             $this->get('social.mailer')->sendAdminNewUser($user$emailLists$contactInvitestrue);
  401.                         } else {
  402.                             $this->get('social.mailer')->sendAdminNewUser($user$emailLists$contactInvitesfalse);
  403.                         }
  404.                         $em->flush();
  405.                         $this->triggerSendEmailConfirmationToUser($user$request);
  406.                         if ($request->isXmlHttpRequest()) {
  407.                             $token = new UsernamePasswordToken($usernull'main'$user->getRoles());
  408.                             $this->get('security.token_storage')->setToken($token);
  409.                             return new JsonResponse(
  410.                                 [
  411.                                     'error_flag' => false,
  412.                                     'redirectUrl' => $this->generateUrl(
  413.                                         'social_frontend_account',
  414.                                         [],
  415.                                         UrlGeneratorInterface::ABSOLUTE_URL
  416.                                     ),
  417.                                 ]
  418.                             );
  419.                         }
  420.                         if (null === $response $event->getResponse()) {
  421.                             $url $this->generateUrl('fos_user_registration_check_email');
  422.                             $response = new RedirectResponse($url);
  423.                         }
  424.                         $dispatcher->dispatch(
  425.                             FOSUserEvents::REGISTRATION_COMPLETED,
  426.                             new FilterUserResponseEvent($user$request$response)
  427.                         );
  428.                         setcookie('userRegistrationModalFlag'1);
  429.                         return $response;
  430.                     } catch (\Exception $exception) {
  431.                         $sentry->captureException($exception);
  432.                         return new RedirectResponse($this->generateUrl('social_user_homepage'));
  433.                     }
  434.                 }
  435.                 if ($request->isXmlHttpRequest()) {
  436.                     $errors $this->getErrorMessages($form);
  437.                     $tokenProvider $this->container->get('security.csrf.token_manager');
  438.                     $token         $tokenProvider->getToken('example')->getValue();
  439.                     return new JsonResponse(
  440.                         [
  441.                             'error_flag' => true,
  442.                             'errors'     => $errors,
  443.                             'token'      => $token,
  444.                         ]
  445.                     );
  446.                 }
  447.             }
  448.             return $this->container->get('templating')->renderResponse('SocialUserBundle:Registration:index_'.$this->container->get('social.theme_manager')->getActiveTheme()['name'].'.html.twig', [
  449.                 'form' => $form->createView()
  450.             ]);
  451.         } catch (\Exception $exception) {
  452.             $sentry->captureException($exception);
  453.             return new RedirectResponse($this->generateUrl('social_user_homepage'));
  454.         }
  455.     }
  456.     public function addCreditUserHistory($user$packageList)
  457.     {
  458.         $this->subscriptionLogger->info("In addCreditUserHistory");
  459.         try {
  460.             $em $this->getDoctrine()->getManager();
  461.             if ($this->getParameter('social_credits_mode_activated') == 1) {
  462.                 $this->subscriptionLogger->info("In addCreditUserHistory social_credits_mode_activated is true");
  463.                 $historyCredits = new CreditUserHistoryEntity();
  464.                 $historyCredits->setUserId($user);
  465.                 $historyCredits->setAction('Convert bonus to credits');
  466.                 $historyCredits->setType(CreditUserHistoryEntity::ACTION_TYPE_CONVERTO_FROM_BONUS);
  467.                 $historyCredits->setCost($packageList->getValue());
  468.                 $historyCredits->setTimestamp(new \DateTime('now'));
  469.                 $historyCredits->setIsFromBonus(true);
  470.                 $em->persist($historyCredits);
  471.                 $em->flush();
  472.             }
  473.         } catch (\Exception $exception) {
  474.             $this->subscriptionLogger->error("error while adding credits to user " $exception->getMessage());
  475.             $this->get('sentry.client')->captureException($exception);
  476.         }
  477.         $this->subscriptionLogger->info("completed addCreditUserHistory");
  478.     }
  479.     public function unsubscribeEmailListInSentsio($emailTrafficUserExists$sentry)
  480.     {
  481.         $em $this->getDoctrine()->getManager();
  482.         $client HttpClient::create();
  483.         $sentSioHistoryData $em->getRepository(SentsioImportHistory::class)->findBy(['emailList' => $emailTrafficUserExists]);
  484.         foreach ($sentSioHistoryData as $sentSioHistory) {
  485.             try {
  486.                 $email $emailTrafficUserExists->getEmail();
  487.                 // All EmailLists from sentsio
  488.                 $existingEmailInSentsio $client->request('GET'"https://sentsio.com/api/v1/subscribers/email/$email", [
  489.                     'query' => [
  490.                         'api_token' => $sentSioHistory->getToken(),
  491.                         'email' => $email
  492.                     ]
  493.                 ]);
  494.                 $response json_decode($existingEmailInSentsio->getContent(), true)['subscribers'];
  495.                 foreach ($response as $item) {
  496.                     $uID $item['uid'];
  497.                     $listId $item['list_uid'];
  498.                     // Update Tag of Subscriber
  499.                     $client->request('PATCH'"https://sentsio.com/api/v1/subscribers/$uID", [
  500.                         'query' => [
  501.                             'api_token' => $sentSioHistory->getToken(),
  502.                             'uid' => $uID,
  503.                             'EMAIL' => $email,
  504.                             'tag' => "email_with_signUp_made"
  505.                         ]
  506.                     ]);
  507.                     // UNSUBSCRIBE EmailList from Sentsio
  508.                     $client->request('PATCH'"https://sentsio.com/api/v1/lists/$listId/subscribers/$uID/unsubscribe", [
  509.                         'query' => [
  510.                             'api_token' => $sentSioHistory->getToken(),
  511.                         ]
  512.                     ]);
  513.                 }
  514.             } catch (\Exception $exception) {
  515.                 $sentry->captureException($exception);
  516.             }
  517.         }
  518.         return true;
  519.     }
  520.     private function getErrorMessages(Form $form)
  521.     {
  522.         $errors = [];
  523.         foreach ($form->getErrors() as $error) {
  524.             if ($form->isRoot()) {
  525.                 $errors['#'][] = $error->getMessage();
  526.             } else {
  527.                 $errors[] = $error->getMessage();
  528.             }
  529.         }
  530.         foreach ($form->all() as $child) {
  531.             if (!$child->isValid()) {
  532.                 $errors[$child->getName()] = $this->getErrorMessages($child);
  533.             }
  534.         }
  535.         return $errors;
  536.     }
  537.     /**
  538.      * @return Response
  539.      */
  540.     public function startDateSectionHomepageAction()
  541.     {
  542.         return $this->render('SocialUserBundle:Registration:section_start_date_homepage.html.twig');
  543.     }
  544.     /**
  545.      * @return Response
  546.      */
  547.     public function ourLoversSectionHomepageAction()
  548.     {
  549.         return $this->render('SocialUserBundle:Registration:section_our_lovers_homepage.html.twig');
  550.     }
  551.     /**
  552.      * @return Response
  553.      */
  554.     public function topMembersSectionHomepageAction()
  555.     {
  556.         $em           $this->get('doctrine.orm.entity_manager');
  557.         $newestUsers  $em->getRepository('SocialUserBundle:User')->findNewestUsers();
  558.         $onlineUsers  $em->getRepository('SocialUserBundle:User')->getOnlineUsers();
  559.         $popularUsers $em->getRepository('SocialUserBundle:User')->getPopularUsers();
  560.         return $this->render(
  561.             'SocialUserBundle:Registration:section_top_members_homepage.html.twig',
  562.             ['newest_users' => $newestUsers'online_users' => $onlineUsers'popular_users' => $popularUsers]
  563.         );
  564.     }
  565.     /**
  566.      * @return Response
  567.      */
  568.     public function testimonialsSectionHomepageAction()
  569.     {
  570.         return $this->render('SocialUserBundle:Registration:section_testimonials_homepage.html.twig');
  571.     }
  572.     /**
  573.      * @return Response
  574.      */
  575.     public function supportSectionHomepageAction()
  576.     {
  577.         $newsletterForm $this->createForm(NewsletterType::class, null);
  578.         return $this->render(
  579.             'SocialUserBundle:Registration:section_support_homepage.html.twig',
  580.             ['newsletter_form' => $newsletterForm->createView()]
  581.         );
  582.     }
  583.     /**
  584.      * @param Request $request
  585.      *
  586.      * @return RedirectResponse|Response
  587.      */
  588.     public function step2Action(Request $request)
  589.     {
  590.         // If somehow somebody ends here - redirect to account home
  591.         return new RedirectResponse($this->generateUrl('social_frontend_homepage_account'));
  592.         $translator $this->get('translator');
  593.         $errors     = [];
  594.         if ($request->getMethod() == 'POST') {
  595.             $em $this->get('doctrine.orm.entity_manager');
  596.             $filters $request->get('filters');
  597.             if (count($filters['interest']) == 0) {
  598.                 return $this->render(
  599.                     'SocialUserBundle:Registration:step2.html.twig',
  600.                     ['errors' => [$translator->trans('Please choose at least 1 gender you are interested in.')]]
  601.                 );
  602.             }
  603.             $user $this->getUser();
  604.             $user->setInterestedIn($filters['interest']);
  605.             $this->getUser()->setLastRegistrationStep(2);
  606.             $em->persist($this->getUser());
  607.             $em->flush();
  608.             return $this->redirect($this->generateUrl('social_user_signup_step3'));
  609.         }
  610.         return $this->render('SocialUserBundle:Registration:step2.html.twig', ['errors' => []]);
  611.     }
  612.     /**
  613.      * @param Request $request
  614.      *
  615.      * @return RedirectResponse|Response
  616.      */
  617.     public function step3Action(Request $request)
  618.     {
  619.         $em $this->get('doctrine.orm.entity_manager');
  620.         $form $this->createForm(UserType::class, $this->getUser(), [
  621.             'destination' => ['step-3'],
  622.             'locale' => $request->getLocale()
  623.         ]);
  624.         if ($request->getMethod() == 'POST') {
  625.             $form->submit($request->request->get($form->getName()));
  626.             if ($form->isValid()) {
  627.                 /** @var User $user */
  628.                 $user $form->getData();
  629.                 if ($user->getImage() && $user->getDeleteProfilePictureId() == $user->getImage()->getId()) {
  630.                     $user->setImage(null);
  631.                 }
  632.                 $user->setLastRegistrationStep(4); // this means that it will skip the invitation step. but we also need to trigger the email sending
  633.                 if ($user->getNumberLogins() == 0) {
  634.                     $user->setNumberLogins(1);
  635.                 }
  636.                 $em->persist($user);
  637.                 $em->flush();
  638.                 if ($user->getNewLocation() !== null) {
  639.                     setcookie('userRegistrationModalFlag'0);
  640.                 }
  641.                 /** @var UserSignupPollData $userPollSignUp */
  642.                 $userPollSignUp $this->getDoctrine()->getRepository(UserSignupPollData::class)
  643.                                        ->findOneBy(['userReference' => $user]);
  644.                 if ($userPollSignUp) {
  645.                     if ($userPollSignUp->getPollReference()) {
  646.                         /** @var TrafficPool $trafficPoll */
  647.                         $trafficPoll $userPollSignUp->getPollReference();
  648.                         $conversions $trafficPoll->getConversions();
  649.                         if ($conversions) {
  650.                             /** @var Conversions $conversion */
  651.                             foreach ($conversions as $conversion) {
  652.                                 if ($conversion->getActive()) {
  653.                                     $client = new Client();
  654.                                     $random time() + rand(19999);
  655.                                     $url $conversion->getUrl();
  656.                                     $url .= '&cb='.$random;
  657.                                     $url .= '&cti='.$user->getId().'-'.$trafficPoll->getCode();
  658.                                     $this->get('sentry.client')->captureMessage($url);
  659.                                     try {
  660.                                         $response $client->get($url);
  661.                                         $this->get('sentry.client')->captureMessage($response->getStatusCode());
  662.                                     } catch (\Exception $exception) {
  663.                                         $this->get('sentry.client')->captureException($exception);
  664.                                     }
  665.                                 }
  666.                             }
  667.                         }
  668.                     }
  669.                 }
  670.                 if ($this->getUser() instanceof User) {
  671.                     if ($this->getUser()->getNewLocation() !== null) {
  672.                         setcookie('userRegistrationModalFlag'0time() - 3600'/');
  673.                     }
  674.                 }
  675.                 return $this->json(['error_flag' => false]);
  676.             }
  677.             return $this->json([
  678.                     'error_flag' => true,
  679.                     'data'       => $this->recursiveFormErrors(
  680.                         $form->getErrors(truefalse),
  681.                         [$form->getName()]
  682.                     ),
  683.                 ]);
  684.         }
  685.         return $this->redirect($this->generateUrl('social_frontend_homepage_account'));
  686.     }
  687.     private function recursiveFormErrors(FormErrorIterator $formErrors, array $prefixes)
  688.     {
  689.         $errors = [];
  690.         foreach ($formErrors as $formError) {
  691.             if ($formError instanceof FormErrorIterator) {
  692.                 $errors array_merge(
  693.                     $errors,
  694.                     $this->recursiveFormErrors($formErrorarray_merge($prefixes, [$formError->getForm()->getName()]))
  695.                 );
  696.             } elseif ($formError instanceof FormError) {
  697.                 $errors[implode('_'$prefixes)][] = $formError->getMessage();
  698.             }
  699.         }
  700.         return $errors;
  701.     }
  702.     public function registerAction(Request $request)
  703.     {
  704.         $user $this->userManager->createUser();
  705.         $user->setEnabled(true);
  706.         $event = new GetResponseUserEvent($user$request);
  707.         $this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE$event);
  708.         if (null !== $event->getResponse()) {
  709.             return $event->getResponse();
  710.         }
  711.         $form $this->createForm(UserType::class, $user);
  712.         $form->handleRequest($request);
  713.         if ($form->isSubmitted()) {
  714.             if ($form->isValid()) {
  715.                 $event = new FormEvent($form$request);
  716.                 $this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS$event);
  717.                 $this->userManager->updateUser($user);
  718.                 if (null === $response $event->getResponse()) {
  719.                     $url      $this->generateUrl('fos_user_registration_confirmed');
  720.                     $response = new RedirectResponse($url);
  721.                 }
  722.                 $this->eventDispatcher->dispatch(
  723.                     FOSUserEvents::REGISTRATION_COMPLETED,
  724.                     new FilterUserResponseEvent($user$request$response)
  725.                 );
  726.                 return $response;
  727.             }
  728.             $event = new FormEvent($form$request);
  729.             $this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_FAILURE$event);
  730.             if (null !== $response $event->getResponse()) {
  731.                 return $response;
  732.             }
  733.         }
  734.         return $this->render(
  735.             '@FOSUser/Registration/register.html.twig',
  736.             [
  737.                 'form' => $form->createView(),
  738.             ]
  739.         );
  740.     }
  741.     public function renderPartialProfileConfirmationAction(Request $request)
  742.     {
  743.         $form $this->createForm(
  744.             UserType::class,
  745.             $this->getUser(),
  746.             ['destination' => ['profile-confirmation'], 'locale' => $request->getLocale()]
  747.         );
  748.         return $this->render(
  749.             'SocialUserBundle:Registration:partial_user_profile_confirmation.html.twig',
  750.             ['form' => $form->createView()]
  751.         );
  752.     }
  753.     public function stepProfileUpdateAction(Request $request)
  754.     {
  755.         $em $this->get('doctrine.orm.entity_manager');
  756.         $form $this->createForm(
  757.             UserType::class,
  758.             $this->getUser(),
  759.             ['destination' => ['profile-confirmation'], 'locale' => $request->getLocale()]
  760.         );
  761.         try {
  762.             if ($request->getMethod() == 'POST') {
  763.                 $form->submit($request->request->get($form->getName()));
  764.                 if ($form->isValid()) {
  765.                     /** @var User $user */
  766.                     $user $form->getData();
  767.                     $user->setLastRegistrationStep(4);
  768.                     $em->persist($user);
  769.                     $em->flush();
  770.                     $this->get('social.mailer')->sendAccountConfirmedEmail($user);
  771.                     return $this->redirect($this->generateUrl('social_frontend_homepage_account'));
  772.                 }
  773.                 return $this->json(
  774.                     [
  775.                         'error_flag' => true,
  776.                         'data' => $this->recursiveFormErrors(
  777.                             $form->getErrors(truefalse),
  778.                             [$form->getName()]
  779.                         ),
  780.                     ]
  781.                 );
  782.             }
  783.         } catch (\Exception $exception) {
  784.             return $this->json(
  785.                 [
  786.                     'error_flag' => true,
  787.                     'data' => $this->recursiveFormErrors(
  788.                         $form->getErrors(truefalse),
  789.                         [$form->getName()]
  790.                     ),
  791.                 ]
  792.             );
  793.         }
  794.         return $this->redirect($this->generateUrl('social_frontend_homepage_account'));
  795.     }
  796.     public function renderPartialStep3Action(Request $request)
  797.     {
  798.         $em $this->get('doctrine.orm.entity_manager');
  799.         $form $this->createForm(UserType::class, $this->getUser(), [
  800.             'destination' => ['step-3'],
  801.             'locale' => $request->getLocale()
  802.         ]);
  803.         if ($request->getMethod() == 'POST') {
  804.             $form->submit($request);
  805.             if ($form->isValid()) {
  806.                 /** @var User $user */
  807.                 $user $form->getData();
  808.                 if ($user->getImage() && $user->getDeleteProfilePictureId() == $user->getImage()->getId()) {
  809.                     $user->setImage(null);
  810.                 }
  811.                 $user->setLastRegistrationStep(4); // this means that it will skip the invitation step. but we also need to trigger the email sending
  812.                 $em->persist($user);
  813.                 $em->flush();
  814.                 return $this->redirect($this->generateUrl('social_frontend_homepage_account'));
  815.             }
  816.         }
  817.         return $this->render(
  818.             'SocialUserBundle:Registration:partial_step3.html.twig',
  819.             ['form' => $form->createView()]
  820.         );
  821.     }
  822.     public function renderSetPasswordAction(Request $request)
  823.     {
  824.         $em $this->get('doctrine.orm.entity_manager');
  825.         $form $this->createForm(
  826.             UserType::class,
  827.             $this->getUser(),
  828.             ['destination' => ['set-password'], 'locale' => $request->getLocale()]
  829.         );
  830.         if ($request->getMethod() == 'POST') {
  831.             $form->handleRequest($request);
  832.             if ($form->isValid()) {
  833.                 $user $form->getData();
  834.                 $this->userManager->updateUser($user);
  835.                 $em->persist($user);
  836.                 $em->flush();
  837.                 return $this->json(['error_flag' => false]);
  838.             }
  839.             return $this->json(
  840.                 [
  841.                     'error_flag' => true,
  842.                     'data' => $this->recursiveFormErrors(
  843.                         $form->getErrors(truefalse),
  844.                         [$form->getName()]
  845.                     ),
  846.                 ]
  847.             );
  848.         }
  849.         return $this->render(
  850.             'SocialUserBundle:Registration:partial_user_set_password.html.twig',
  851.             ['form' => $form->createView()]
  852.         );
  853.     }
  854.     /**
  855.      * @param Request $request
  856.      *
  857.      * @return RedirectResponse|Response
  858.      */
  859.     public function step4Action(Request $request)
  860.     {
  861.         $em $this->get('doctrine.orm.entity_manager');
  862.         if ($request->getMethod() == 'POST') {
  863.             $user $this->getUser();
  864.             $user->setLastRegistrationStep(4);
  865.             $em->persist($user);
  866.             $em->flush();
  867.             $this->triggerSendEmailConfirmationToUser($user$request);
  868.             $em->persist($user);
  869.             $em->flush();
  870.             return $this->redirect($this->get('router')->generate('fos_user_registration_check_email'));
  871.         }
  872.         return $this->render('SocialUserBundle:Registration:step4.html.twig');
  873.     }
  874.     /**
  875.      * @param Request $request
  876.      *
  877.      * @return RedirectResponse|Response|null
  878.      */
  879.     public function checkEmailAction(Request $request)
  880.     {
  881.         $user $this->getUser();
  882.         if ($user) {
  883.             if ($this->getUser()->isProfileCompleted()) {
  884.                 return $this->redirect($this->generateUrl('social_frontend_account'));
  885.             } else {
  886.                 return $this->render(
  887.                     '@SocialUser/Registration/checkEmail.html.twig',
  888.                     [
  889.                         'user' => $this->getUser(),
  890.                     ]
  891.                 );
  892.             }
  893.         }
  894.     }
  895.     /**
  896.      * @param Request                $request
  897.      * @param TranslatorInterface    $translator
  898.      * @param EntityManagerInterface $entityManager
  899.      *
  900.      * @return RedirectResponse
  901.      */
  902.     public function resendConfirmationEmailAction(
  903.         Request $request,
  904.         TranslatorInterface $translator,
  905.         EntityManagerInterface $entityManager
  906.     ) {
  907.         try {
  908.             $em $entityManager;
  909.             $this->get('session')->getFlashBag()->add(
  910.                 'notice',
  911.                 $translator->trans('The confirmation email was successfully sent to your email address!')
  912.             );
  913.             /** @var User $user */
  914.             $user $this->getUser();
  915.             $this->triggerSendEmailConfirmationToUser($user$request);
  916.             $em->persist($user);
  917.             $em->flush();
  918.             return $this->redirect($this->get('router')->generate('fos_user_registration_check_email'));
  919.         } catch (\Exception $exception) {
  920.             $this->get('sentry.client')->captureException($exception);
  921.         }
  922.     }
  923.     /**
  924.      * @param Request $request
  925.      * @param string  $token
  926.      *
  927.      * @return null|RedirectResponse|Response
  928.      */
  929.     public function confirmAction(Request $request$token)
  930.     {
  931.         /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
  932.         $userManager $this->get('fos_user.user_manager');
  933.         /** @var User|null $user */
  934.         $user $userManager->findUserByConfirmationToken($token);
  935.         if (null === $user) {
  936.             return $this->redirect($this->generateUrl('social_frontend_homepage_account'));
  937.         }
  938.         if ($user->isEnabled() == false) {
  939.             //            throw new NotFoundHttpException(sprintf('The user #%s - %s is marked as disabled. It cannot be confirmed.', $user->getId(), $user));
  940.             return $this->redirect($this->generateUrl('social_user_homepage'));
  941.         }
  942.         /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
  943.         $dispatcher $this->get('event_dispatcher');
  944.         $user->setConfirmationToken(null);
  945.         //        $user->setEnabled(true);
  946.         $user->setConfirmed(true);
  947.         if ($user->isProfileCompleted()) {
  948.             $this->get('social.mailer')->sendAccountConfirmedEmail($user);
  949.         }
  950.         $event = new GetResponseUserEvent($user$request);
  951.         $dispatcher->dispatch(FOSUserEvents::REGISTRATION_CONFIRM$event);
  952.         $userManager->updateUser($user);
  953.         if (null === $response $event->getResponse()) {
  954.             $url      $this->generateUrl('social_frontend_homepage_account');
  955.             $response = new RedirectResponse($url);
  956.         }
  957.         $dispatcher->dispatch(
  958.             FOSUserEvents::REGISTRATION_CONFIRMED,
  959.             new FilterUserResponseEvent($user$request$response)
  960.         );
  961.         $this->get('social_user.user_authentication_handler')->main($user);
  962.         return $response;
  963.     }
  964.     /**
  965.      * @param User    $user
  966.      * @param Request $request
  967.      */
  968.     private function triggerSendEmailConfirmationToUser(User $userRequest $request)
  969.     {
  970.         $dispatcher $this->container->get('event_dispatcher');
  971.         $form $this->createForm(UserType::class, $user);
  972.         //$formFactory = $this->container->get('fos_user.registration.form.factory');
  973.         //$form = $formFactory->createForm();
  974.         //$form->setData($user);
  975.         $event = new FormEvent($form$request);
  976.         $dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS$event);
  977.     }
  978.     private function replace_spec_char($subject)
  979.     {
  980.         $char_map = [
  981.             "ъ"  => "-",
  982.             "ь"  => "-",
  983.             "Ъ"  => "-",
  984.             "Ь"  => "-",
  985.             "А"  => "A",
  986.             "Ă"  => "A",
  987.             "Ǎ"  => "A",
  988.             "Ą"  => "A",
  989.             "À"  => "A",
  990.             "Ã"  => "A",
  991.             "Á"  => "A",
  992.             "Æ"  => "A",
  993.             "Â"  => "A",
  994.             "Å"  => "A",
  995.             "Ǻ"  => "A",
  996.             "Ā"  => "A",
  997.             "א"  => "A",
  998.             "Б"  => "B",
  999.             "ב"  => "B",
  1000.             "Þ"  => "B",
  1001.             "Ĉ"  => "C",
  1002.             "Ć"  => "C",
  1003.             "Ç"  => "C",
  1004.             "Ц"  => "C",
  1005.             "צ"  => "C",
  1006.             "Ċ"  => "C",
  1007.             "Č"  => "C",
  1008.             "©"  => "C",
  1009.             "ץ"  => "C",
  1010.             "Д"  => "D",
  1011.             "Ď"  => "D",
  1012.             "Đ"  => "D",
  1013.             "ד"  => "D",
  1014.             "Ð"  => "D",
  1015.             "È"  => "E",
  1016.             "Ę"  => "E",
  1017.             "É"  => "E",
  1018.             "Ë"  => "E",
  1019.             "Ê"  => "E",
  1020.             "Е"  => "E",
  1021.             "Ē"  => "E",
  1022.             "Ė"  => "E",
  1023.             "Ě"  => "E",
  1024.             "Ĕ"  => "E",
  1025.             "Є"  => "E",
  1026.             "Ə"  => "E",
  1027.             "ע"  => "E",
  1028.             "Ф"  => "F",
  1029.             "Ƒ"  => "F",
  1030.             "Ğ"  => "G",
  1031.             "Ġ"  => "G",
  1032.             "Ģ"  => "G",
  1033.             "Ĝ"  => "G",
  1034.             "Г"  => "G",
  1035.             "ג"  => "G",
  1036.             "Ґ"  => "G",
  1037.             "ח"  => "H",
  1038.             "Ħ"  => "H",
  1039.             "Х"  => "H",
  1040.             "Ĥ"  => "H",
  1041.             "ה"  => "H",
  1042.             "I"  => "I",
  1043.             "Ï"  => "I",
  1044.             "Î"  => "I",
  1045.             "Í"  => "I",
  1046.             "Ì"  => "I",
  1047.             "Į"  => "I",
  1048.             "Ĭ"  => "I",
  1049.             "И"  => "I",
  1050.             "Ĩ"  => "I",
  1051.             "Ǐ"  => "I",
  1052.             "י"  => "I",
  1053.             "Ї"  => "I",
  1054.             "Ī"  => "I",
  1055.             "І"  => "I",
  1056.             "Й"  => "J",
  1057.             "Ĵ"  => "J",
  1058.             "ĸ"  => "K",
  1059.             "כ"  => "K",
  1060.             "Ķ"  => "K",
  1061.             "К"  => "K",
  1062.             "ך"  => "K",
  1063.             "Ł"  => "L",
  1064.             "Ŀ"  => "L",
  1065.             "Л"  => "L",
  1066.             "Ļ"  => "L",
  1067.             "Ĺ"  => "L",
  1068.             "Ľ"  => "L",
  1069.             "ל"  => "L",
  1070.             "מ"  => "M",
  1071.             "М"  => "M",
  1072.             "ם"  => "M",
  1073.             "Ñ"  => "N",
  1074.             "Ń"  => "N",
  1075.             "Н"  => "N",
  1076.             "Ņ"  => "N",
  1077.             "ן"  => "N",
  1078.             "Ŋ"  => "N",
  1079.             "נ"  => "N",
  1080.             "ʼn"  => "N",
  1081.             "Ň"  => "N",
  1082.             "Ø"  => "O",
  1083.             "Ó"  => "O",
  1084.             "Ò"  => "O",
  1085.             "Ô"  => "O",
  1086.             "Õ"  => "O",
  1087.             "О"  => "O",
  1088.             "Ő"  => "O",
  1089.             "Ŏ"  => "O",
  1090.             "Ō"  => "O",
  1091.             "Ǿ"  => "O",
  1092.             "Ǒ"  => "O",
  1093.             "Ơ"  => "O",
  1094.             "פ"  => "P",
  1095.             "ף"  => "P",
  1096.             "П"  => "P",
  1097.             "ק"  => "Q",
  1098.             "Ŕ"  => "R",
  1099.             "Ř"  => "R",
  1100.             "Ŗ"  => "R",
  1101.             "ר"  => "R",
  1102.             "Р"  => "R",
  1103.             "®"  => "R",
  1104.             "Ş"  => "S",
  1105.             "Ś"  => "S",
  1106.             "Ș"  => "S",
  1107.             "Š"  => "S",
  1108.             "С"  => "S",
  1109.             "Ŝ"  => "S",
  1110.             "ס"  => "S",
  1111.             "Т"  => "T",
  1112.             "Ț"  => "T",
  1113.             "ט"  => "T",
  1114.             "Ŧ"  => "T",
  1115.             "ת"  => "T",
  1116.             "Ť"  => "T",
  1117.             "Ţ"  => "T",
  1118.             "Ù"  => "U",
  1119.             "Û"  => "U",
  1120.             "Ú"  => "U",
  1121.             "Ū"  => "U",
  1122.             "У"  => "U",
  1123.             "Ũ"  => "U",
  1124.             "Ư"  => "U",
  1125.             "Ǔ"  => "U",
  1126.             "Ų"  => "U",
  1127.             "Ŭ"  => "U",
  1128.             "Ů"  => "U",
  1129.             "Ű"  => "U",
  1130.             "Ǖ"  => "U",
  1131.             "Ǜ"  => "U",
  1132.             "Ǚ"  => "U",
  1133.             "Ǘ"  => "U",
  1134.             "В"  => "V",
  1135.             "ו"  => "V",
  1136.             "Ý"  => "Y",
  1137.             "Ы"  => "Y",
  1138.             "Ŷ"  => "Y",
  1139.             "Ÿ"  => "Y",
  1140.             "Ź"  => "Z",
  1141.             "Ž"  => "Z",
  1142.             "Ż"  => "Z",
  1143.             "З"  => "Z",
  1144.             "ז"  => "Z",
  1145.             "а"  => "a",
  1146.             "ă"  => "a",
  1147.             "ǎ"  => "a",
  1148.             "ą"  => "a",
  1149.             "à"  => "a",
  1150.             "ã"  => "a",
  1151.             "á"  => "a",
  1152.             "æ"  => "a",
  1153.             "â"  => "a",
  1154.             "å"  => "a",
  1155.             "ǻ"  => "a",
  1156.             "ā"  => "a",
  1157.             'A¡' => 'a',
  1158.             "б"  => "b",
  1159.             "þ"  => "b",
  1160.             "ĉ"  => "c",
  1161.             "ć"  => "c",
  1162.             "ç"  => "c",
  1163.             "ц"  => "c",
  1164.             "ċ"  => "c",
  1165.             "č"  => "c",
  1166.             "Ч"  => "ch",
  1167.             "ч"  => "ch",
  1168.             "д"  => "d",
  1169.             "ď"  => "d",
  1170.             "đ"  => "d",
  1171.             "ð"  => "d",
  1172.             "è"  => "e",
  1173.             "ę"  => "e",
  1174.             "é"  => "e",
  1175.             "ë"  => "e",
  1176.             "ê"  => "e",
  1177.             "е"  => "e",
  1178.             "ē"  => "e",
  1179.             "ė"  => "e",
  1180.             "ě"  => "e",
  1181.             "ĕ"  => "e",
  1182.             "є"  => "e",
  1183.             "ə"  => "e",
  1184.             "ф"  => "f",
  1185.             "ƒ"  => "f",
  1186.             "ğ"  => "g",
  1187.             "ġ"  => "g",
  1188.             "ģ"  => "g",
  1189.             "ĝ"  => "g",
  1190.             "г"  => "g",
  1191.             "ґ"  => "g",
  1192.             "ħ"  => "h",
  1193.             "х"  => "h",
  1194.             "ĥ"  => "h",
  1195.             "i"  => "i",
  1196.             "ï"  => "i",
  1197.             "î"  => "i",
  1198.             "í"  => "i",
  1199.             "ì"  => "i",
  1200.             "į"  => "i",
  1201.             "ĭ"  => "i",
  1202.             "ı"  => "i",
  1203.             "и"  => "i",
  1204.             "ĩ"  => "i",
  1205.             "ǐ"  => "i",
  1206.             "ї"  => "i",
  1207.             "ī"  => "i",
  1208.             "і"  => "i",
  1209.             "й"  => "j",
  1210.             "ĵ"  => "j",
  1211.             "ķ"  => "k",
  1212.             "к"  => "k",
  1213.             "ł"  => "l",
  1214.             "ŀ"  => "l",
  1215.             "л"  => "l",
  1216.             "ļ"  => "l",
  1217.             "ĺ"  => "l",
  1218.             "ľ"  => "l",
  1219.             "м"  => "m",
  1220.             "ñ"  => "n",
  1221.             "ń"  => "n",
  1222.             "н"  => "n",
  1223.             "ņ"  => "n",
  1224.             "ŋ"  => "n",
  1225.             "ň"  => "n",
  1226.             "ø"  => "o",
  1227.             "ó"  => "o",
  1228.             "ò"  => "o",
  1229.             "ô"  => "o",
  1230.             "õ"  => "o",
  1231.             "о"  => "o",
  1232.             "ő"  => "o",
  1233.             "ŏ"  => "o",
  1234.             "ō"  => "o",
  1235.             "ǿ"  => "o",
  1236.             "ǒ"  => "o",
  1237.             "ơ"  => "o",
  1238.             "п"  => "p",
  1239.             "ŕ"  => "r",
  1240.             "ř"  => "r",
  1241.             "ŗ"  => "r",
  1242.             "р"  => "r",
  1243.             "ş"  => "s",
  1244.             "ś"  => "s",
  1245.             "ș"  => "s",
  1246.             "š"  => "s",
  1247.             "с"  => "s",
  1248.             "ŝ"  => "s",
  1249.             "т"  => "t",
  1250.             "ț"  => "t",
  1251.             "ŧ"  => "t",
  1252.             "ť"  => "t",
  1253.             "ţ"  => "t",
  1254.             "ù"  => "u",
  1255.             "û"  => "u",
  1256.             "ú"  => "u",
  1257.             "ū"  => "u",
  1258.             "у"  => "u",
  1259.             "ũ"  => "u",
  1260.             "ư"  => "u",
  1261.             "ǔ"  => "u",
  1262.             "ų"  => "u",
  1263.             "ŭ"  => "u",
  1264.             "ů"  => "u",
  1265.             "ű"  => "u",
  1266.             "ǖ"  => "u",
  1267.             "ǜ"  => "u",
  1268.             "ǚ"  => "u",
  1269.             "ǘ"  => "u",
  1270.             "в"  => "v",
  1271.             "ý"  => "y",
  1272.             "ы"  => "y",
  1273.             "ŷ"  => "y",
  1274.             "ÿ"  => "y",
  1275.             "ź"  => "z",
  1276.             "ž"  => "z",
  1277.             "ż"  => "z",
  1278.             "з"  => "z",
  1279.             "ſ"  => "z",
  1280.             "™"  => "tm",
  1281.             "Ä"  => "ae",
  1282.             "Ǽ"  => "ae",
  1283.             "ä"  => "ae",
  1284.             "ǽ"  => "ae",
  1285.             "ij"  => "ij",
  1286.             "IJ"  => "ij",
  1287.             "я"  => "ja",
  1288.             "Я"  => "ja",
  1289.             "Э"  => "je",
  1290.             "э"  => "je",
  1291.             "ё"  => "jo",
  1292.             "Ё"  => "jo",
  1293.             "ю"  => "ju",
  1294.             "Ю"  => "ju",
  1295.             "œ"  => "oe",
  1296.             "Œ"  => "oe",
  1297.             "ö"  => "oe",
  1298.             "Ö"  => "oe",
  1299.             "щ"  => "sch",
  1300.             "Щ"  => "sch",
  1301.             "ш"  => "sh",
  1302.             "Ш"  => "sh",
  1303.             "ß"  => "ss",
  1304.             "Ü"  => "ue",
  1305.             "Ж"  => "zh",
  1306.             "ж"  => "zh",
  1307.         ];
  1308.         return strtr($subject$char_map);
  1309.     }
  1310. }