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

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